I happened to come across the BeautifulSoup library from python which enables you to "scrape" or extract content from the web. It does this by allowing you to create a BeautifulSoup object from a website's URL, which subsequently contains the html content for that particular website. Once the BeautifulSoup object is created, you can use its member functions to search for specific content that you are interested in. Of course, this requires inspecting the html source code beforehand so that you know which tags to look for. This is essentially how Google's search engine crawls the web and searches for relevant sites.
The reason this library picqued my interest was because of my casual interest in finance and stock market investing. This interest dates back to college, where at one point I was fascinated by the prospect of becoming an investment banker (however, after hearing some horror stories, I'm kind of glad that didn't work out for me). Anyhow, as a small investor I simply wanted to collect information about certain stocks that wasn't always readily available online in the form in which I wanted to see it.
As an initial exercise to test out BeautifulSoup's features, I wanted to generate a list of all dividend stocks in the three major indexes - Nasdaq, S&P 500, and the Dow. The problem with most stock market sites is that there always seems to be some necessary information missing from a stock quote. I've tried using everything from CNBC to Investor's Business Daily, but there was always something lacking or difficult to find in terms of filtering out a subset of stocks that fit a certain criteria. In this case, I wanted a list of all the top dividend stocks, along with their market cap and 52-week change.
At first, Yahoo! Finance turned out to be the best resource for me, because it contained two out of the above three pieces of information, the dividend yield and market cap. However, the 52-week % Change was stored on a separate page, the "Statistics" page for that particular stock quote. This wouldn't have been a problem, except for the fact that the "Statistics" page data was rendered in javascript as opposed to html. This would require the use of a heavyweight library such as Splinter or Selenium, so after some more searching, I found another resource that was rendered in pure html. This resource was Barron's. Javascript web scraping is still an important topic, however, and something that I will cover in a later post.
I realized that I would have to obtain information separately for each of the major indexes that I was interested in. Thus, I created a common base class called Index which would store information on all stocks in a particular index, and create a list of Stock objects for all the companies that the Index contained. I will go over the Stock class definition shortly.
Below is the first part of my Index class definition, showing the constructor.
class Index: 'Common base class for all indexes' index_count = 0 def __init__(self, name, index_file=None, index_link=None): self.name = name self.index_file = index_file self.index_link = index_link self.index_dict = {} self.stock_list = [] self.stock_data = [] self.out_file = '../docs/' + name.lower() + '-dividend-stocks-sorted.csv' Index.index_count += 1
Notice that the index_file and index_link variables are optional. This is because I obtain the Nasdaq stock list from a CSV file that is downloaded off Nasdaq's web site, whereas I obtain the stock lists for both the S&P 500 and the Dow from Wikipedia. The create_dict() member function, shown below, handles the three separate mechanisms for generating stocks associated with the indexes above. Essentially, a new dictionary called index_dict is created, with the company's ticker symbol and company name forming the key-value pair stored in the dictionary.
Let's move on to the create_dict() member function belonging to Index.
def create_dict(self): if self.name == 'Nasdaq': with open(self.index_file) as csv_file: read_csv = csv.reader(csv_file, delimiter=',') for row in read_csv: if row[1].find('iShares') == -1 and row[1].find('iPath') == -1: self.index_dict[row[0]] = row[1] elif self.name == 'S&P 500': self.index_wiki_page = urllib2.urlopen(self.index_link) self.soup = BeautifulSoup(self.index_wiki_page, 'html.parser') #Store the list of s&p 500 components in dictionary for a in self.soup.findAll('table', {'class': 'wikitable sortable'}, limit=1): for b in a.findAll('tr'): count = 1 for c in b.findAll('td', limit=2): if count == 1: stock_symbol = c.text count += 1 elif count == 2: company_name = c.text print 'c.text = ' + c.text self.index_dict[stock_symbol] = company_name count = 1 elif self.name == 'Dow 30': self.index_wiki_page = urllib2.urlopen(self.index_link) self.soup = BeautifulSoup(self.index_wiki_page, 'html.parser') #Store the list of dow 30 components in dictionary for a in self.soup.findAll('table', {'class': 'wikitable sortable'}): for b in a.findAll('tr'): count = 1 for c in b.findAll('td', limit=3): if count == 1: company_name = c.text count += 1 elif count == 2: count += 1 elif count == 3: stock_symbol = c.text self.index_dict[stock_symbol] = company_name count = 1
Lines 2-7 above handle the opening of the CSV file that stores a list of all Nasdaq dividend stocks. However, one thing to keep in mind is that there are also ETFs and other funds associated with a particular index; I am not interested in obtaining data for these, only for actual companies. This is why I have the if statement in line 6 - it helps filter out some, but not all, of these unwanted funds from the CSV file. Additional filtering will be done in a later step.
Lines 8-24 and 25-42 are essentially the same mechanisms, but for the S&P and Dow, respectively. The urllib2.urlopen() function from the BeautifulSoup library is used to load the Wikipedia html page that stores the list of index components. Then, this page is given as an argument to the BeautifulSoup constructor in order to create a self.soup object, which stores the pure text from the html on that page.
Once the BeautifulSoup object is created, I use the self.soup.findAll() function to obtain all the text corresponding to a specific tag. This requires inspection of the html source code (right click anywhere on page -> view source). Inspection of the html for the Wikipedia page revealed that the company names for the index were stored within a table corresponding to the 'wikitable-sortable' class. However, two additional inner loops are required to extract the text within the tr (tablerow) and td (tabledata) elements within this table. The tr element stores all the information displayed for one particular stock, while the 1st and 3rd td elements within a tr element store the company name and ticker symbol, respectively. This is why the loop is calibrated the way that it is, with the count variable being reset after reaching 3.
Once I obtain these two pieces of text, I store them into self.index_dict, with the ticker symbol as the key value corresponding to a particular company name. Once our Index object's dictionary is fully populated, the next step is to add stocks to the Index's stock list. However, in order to add a stock to the list, we first have to define a type of Stock object that stores the data which we are after. The Stock class definition is shown below:
class Stock: 'Common base class for all stocks' stock_count = 0 def __init__(self, symbol, company): self.symbol = symbol self.company = company self.data = [] Stock.stock_count += 1 def query_stock_symbol(self): # add wait times in between getting each player's data to prevent overload wait_time = round(max(5, 10 + random.gauss(0,3)), 2) time.sleep(wait_time) #create a new beautiful soup object that can query the ticker symbol from barron's stock_link = 'http://www.barrons.com/quote/stock/us/xnas/%s' % (self.symbol) print "stock_link: " + stock_link page = requests.get(stock_link) if page.status_code == 404: stock_link = 'http://www.barrons.com/quote/stock/us/xnys/%s?mod=DNH_S' % (self.symbol) stock_page = urllib2.urlopen(stock_link) self.soup = BeautifulSoup(stock_page, 'html.parser') for a in self.soup.findAll('span', {'class':'market__price'}): print a.text stock_price_str = a.text.replace(',', '') if stock_price_str != 'N/A': self.stock_price = float(stock_price_str) else: self.stock_price = None for a in self.soup.findAll('div', {'class': 'nutrition'}): for b in a.findAll('td'): print b.text self.data.append(b.text) self.market_cap = None for i in xrange(0, len(self.data)): if self.data[i] == 'Market Value': self.market_cap = self.data[i+1] elif self.data[i] == 'Ytd net Change': self.ytd_net_change_str = self.data[i+1].strip('%') if self.ytd_net_change_str != 'N/A': self.ytd_net_change = float(self.ytd_net_change_str) else: self.ytd_net_change = -1 elif self.data[i] == 'Div & Yield': div_amount_str = self.data[i+1].split(' (')[0].strip(' ') div_amount_str = div_amount_str.strip('$') div_yield_str = self.data[i+1].split(' (')[1].strip(')') div_yield_str = div_yield_str.strip('%') if div_amount_str != 'N/A': self.div_amount = float(div_amount_str) self.div_yield = float(div_yield_str) else: self.div_amount = None self.div_yield = None def display_count(self): print "Total Stocks %d" % Stock.stock_count def display_stock(self): print "Company: ", self.company, ", Ticker Symbol: ", self.symbol
We see that the constructor takes two required arguments, symbol and company (which, if you recall, we are deriving from Index's member function create_dict()). Additionally, self.data is being initialized to an empty list. The query_stock_symbol() method handles the extraction of data from the particular stock quote page on barrons.com. I use this method to collect several key pieces of information, including the market cap, 52-week % change, and dividend yield. Now that our stock class is fully defined, we can jump back to finishing up the Index class. We will need a member function to add stocks to the Index object's stock list. The Index.add_stocks() function is shown below:
def add_stocks(self): for key, value in self.index_dict.items(): new_stock = Stock(key, value) new_stock.query_stock_symbol() if new_stock.div_yield != None: self.stock_list.append(new_stock) #Sort the stock list by yield amount, in desecending order self.stock_list.sort(key=lambda stock: stock.div_yield, reverse=True)
Essentially, I create a new Stock object and then use its query_stock_symbol method to extract its data. Remember that we are only interested in dividend stocks - this is why I added an extra if condition to check whether the value of div_yield exists or not. Once I have finished populating the stock list, I sort the list in descending order using Python's sort() feature. I used a simple lambda function as my key value argument for the sort() method (not to be confused with a dictionary key). The lambda function evaluates to the value of the stock's div_yield member variable.
Great - we're almost done! However, we still need to output the data to a CSV file so that we can actually visualize it. This task is handled in the from_dict_to_csv() function, shown below.
def from_dict_to_csv(self): self.add_stocks() self.headings = ['Company','Symbol','Current Price','Market Cap','Dividend', 'Yield', '52-Week Return'] for i in xrange(0, len(self.stock_list)): new_dict = {} new_dict['Company'] = self.stock_list[i].company new_dict['Symbol'] = self.stock_list[i].symbol new_dict['Current Price'] = self.stock_list[i].current_price new_dict['Market Cap'] = self.stock_list[i].market_cap new_dict['Dividend'] = self.stock_list[i].div_amount if self.stock_list[i].div_yield != None: new_dict['Yield'] = str(self.stock_list[i].div_yield) + '%' else: new_dict['Yield'] = 'N/A' if myNewStockList[i].returns != None: new_dict['52-Week Return'] = str(self.stock_list[i].returns) + '%' else: new_dict['52-Week Return'] = 'None' self.stock_data.append(new_dict) try: with open(self.out_file, "wb") as csv_file: writer = csv.DictWriter(csv_file, fieldnames=self.headings, dialect='excel', delimiter=',', quoting=csv.QUOTE_NONNUMERIC) writer.writeheader() for data in self.stock_data: writer.writerow(data) except IOError as (errno, strerror): print("I/O error({0}): {1}".format(errno, strerror))
Nothing too fancy here, just a straightforward iteration through the stock list and utilizing python's csv module to write the data to an output file. The remainder of my overall program, stock_data.py, is shown below. Everything is encapsulated underneath the global function generate_dividend_stocks().
def generate_dividend_stocks(): nasdaq_file = '../docs/dividend-stocks-nasdaq.csv' nasdaq_index = Index('Nasdaq', nasdaq_file) nasdaq_index.create_dict() nasdaq_index.from_dict_to_csv() sp_link = 'https://en.wikipedia.org/wiki/List_of_S%26P_500_companies' sp_index = Index('S&P 500', sp_link) sp_index.create_dict() sp_index.from_dict_to_csv() dow_link = 'https://en.wikipedia.org/wiki/Dow_Jones_Industrial_Average#Components' dow_index = Index('Dow', dow_link) dow_index.create_dict() dow_index.from_dict_to_csv() def main(): generate_dividend_stocks() if __name__ == '__main__': sys.exit(main())
Of course, you could extend the OOP functionality even further, possibly creating a StockMarket object that stores multiple indexes, but I strayed away from doing this initially just for simplicity. That's it for this tutorial! In my next post, I will discuss what we can do with this data, now that we have collected it all in one place, as well as further knobs/tweaks we can add to the program above. Thanks for reading!


{{post.headline}} {{ ' 📺' if post.hasVideo else '' }}
{{ post.abstractAsHtml | safe }}
{% extends "_focus.html" %} {% block pagename %}404{% endblock %} {% block canonicalUrl %}{% endblock %} {% block pageTitlePrefix %}404{% endblock %} {% block head %} {% endblock %} {% block content %}
Sorry, the page you were looking for was not found.
Did you mean any of the latest 5 articles, see below?
If not you might restart from the home page.
{{ post.abstractAsHtml | safe }}


I just started downloading the vista RTM of the msdn website
Ken Egozi has created a c# and vb view engine for castle. It’s not yet available for download but looks promising
You can check it out at : AspView - Yet another MonoRail ViewEngine
As I mentioned previously that I do like boo but i miss intellisense in visual studio and let’s face it at this moment NOTHING beats visual studio as an IDE. Although sharpdevelop scores a lot higher than eclipse in my book. And what an amazing tool they built with so little resources in comparison to the other IDE projects.
I like c# obviously but have been toying around with ironpython a little lately. Once i pass the decorator bit I’d sure love to port the brail view engine to an ironpython view engine (the only problem i see there is that i don’t have time :S to really do it.)
Anyway I thought I might share with you what i have planned as non-workrelated projects for the year that is to come.
- Finish nblogr
- Make nblogr work on linux and on mysql and/or postgres
- Create the ironpython view engine (from here onwards i want to be able to use ironpython as my primary language)
- Add forums to nblogr
- Add CMS capabilities to nblogr (very distant future)
Let me know what you think about the ironpython view engine ?
As stated before I would love some help in any one of my side projects of course. Just drop me a line and I’ll figure out where to fit you in :)
I whished I had some more interesting stuff to talk about but the last 5-6 weeks I’ve been buried in some application and hoping to finish it this week.
del.icio.us tags: Castle, Brail, AspView, NBlogr, Programming, IronPython
A friend of mine just passed me on this link
http://labs.live.com/photosynth/view.html?collection=sanmarco/index1.sxs
_
Welcome to Photosynth, a new technology from Microsoft Live Labs that takes a large collection of photos of a place or an object, analyzes them for similarities, and displays them in a reconstructed three-dimensional space.
We’ve assembled a few collections for you to play with, and we’re working on adding more. In the future you’ll be able to “photosynthesize” your own photos, but we aren’t there yet.
_
del.icio.us tags: Cool stuff, microsoft preview
Over the weekend I got the idea of learning ironpython by moving the codebase that I have for nblogr to ironpython script and compiling it.
Everything went fine until I had to decorate a method to make it cache/participate in a transaction/set a layout on a controller because ironpython in all its beauty doesn’t support attributes on methods or classes.
I’m also missing a reference for ironpython. Something that shows the available functions and the syntax for inheritance etc. which slowed me down of course.
Why do I want a dynamic language ?
The 2 main reasons are : Duck typing and readable anonymous functions. In c# there is the concept of anonymous delegates but that code really looks like it has been hit by a train, ugly.
I’ve been writing in boo for a while now just as a templating language and yes I like boo a lot. It combines the nice features of python with the c# language in a wrist friendly way. (I never got the point of wrist friendly thing until I got carpal tunnel syndrome, now it suddenly is a major issue)
I sure wish there would be a language service for visual studio to do boo development but I’ve been using sharp develop 2.1 to check it out.
SharpDevelop 2.1 is a nice piece of work definitely for an open source IDE’, it beats eclipse in my book
In boo everything is an object also your functions and expressions (read it has anonymous functions). Boo is strong typed but mimics duck typing in some form.
To conclude this little intermezzo : my next project will be written in boo :)
On the ajax library front I would have to report that I haven ‘t looked at atlas/ms ajax since the beginning of september . I had decided to use it again when they finally release the framework. So I’ve been checking out these other libraries that are out there. I checked out jquery which is a cool library but it is also slower in execution than the other ones.
The next one on the list was scriptaculous and that is the one I’ve been using in my projects now. Scriptaculous does exactly what is expected and uses the javascript prototype model which happens to be one i like :)
The move from the guys at MS to make their ajax extensions based on prototype was surprising but very positive in my book :) So when they release it i’ll look at creating an javascript provider for nblogr so that you would be able to switch between your favourite library (we have plans to support the major libraries out of the box.)
del.icio.us tags: Boo, IronPython, Programming, General
A while ago i posted that I was hiring somebody.
Well first of all ==> It’s not easy to find somebody
Secondly this might have been jumping the gun a bit because in light of some recent developments I’ve decided to move my whole operation to Welington aka “Silicon Welly”.Probably I’ll have to look into hiring somebody again around may-june next year.
So the goal is to be up and running in Wellington on the 1st of march.
I won’t be boring you with all the reasons why I think Wellington is a better place to be than New Plymouth for a technology company. But one of the main ones would be that cows don’t really need websites or UI’s.
I hope I’ll find myself a proper place to settle. I’m looking for a reasonably small house (not shed or likewise) with a garden, preferrably one that will hold it’s ground and not slide of the mountain when it rains.
Looking forward to moving there :)
If so then maybe this post will give you some more clarity. It might also give your manager the push in the right direction.
Yesterday I had to implement workflow in an application. I had never used it before, and kind of feared that it was going to take me a couple of days to get the hang of it.
Well 2 hours later I had my test workflow going so it isn’t hard at all. If I can do it in that amount of time I’m sure many of you can beat me.
Now I wanted to host the workflow runtime in my container and this is how I went about it:
I made 2 wrapper properties in a settings class :
public static class SeshatAppSettings
{
public static WorkflowRuntime WorkflowRuntime
{
get
{
return HttpContext.Current.Application[“WorkflowRuntime”] as WorkflowRuntime;
}
set
{
HttpContext.Current.Application[“WorkflowRuntime”] = value;
}
}
public static ManualWorkflowSchedulerService WorkflowScheduler
{
get
{
return WorkflowRuntime.GetService(typeof(ManualWorkflowSchedulerService)) as ManualWorkflowSchedulerService;
}
}
}
The next thing that comes to mind is, hey I need to start this when my application starts (start, app starts == IStartable). Because the workflow is hosted in asp.net we need a persistence medium. I chose to stay with the standard workflow foundation sql persistence service. And that implementation goes a bit like this :
public class WorkflowHost : IStartable
{
#region IStartable Members
///
/// Starts this instance.
///
public void Start()
{
// Create an instance of the workflowRuntime
WorkflowRuntime workflowRuntime = new WorkflowRuntime();
// Add a manual scheduling service
ManualWorkflowSchedulerService manualService = new ManualWorkflowSchedulerService();
workflowRuntime.AddService(manualService);
// Add our persistence
AddPersistenceService(workflowRuntime);
// Start the workflow runtime
workflowRuntime.StartRuntime();
// Store it in a place so that the whole application can get to it.
SeshatAppSettings.WorkflowRuntime = workflowRuntime;
}
///
/// Stops this instance.
///
public void Stop()
{
WorkflowRuntime workflowRuntime = SeshatAppSettings.WorkflowRuntime;
workflowRuntime.StopRuntime();
}
#endregion
private void AddPersistenceService(WorkflowRuntime runtime)
{
// Create the SqlWorkflowPersistenceService.
string connectionString = “Initial Catalog=WorkflowPersistenceStore;Data Source=localhost;Integrated Security=SSPI;”;
bool unloadOnIdle = true;
TimeSpan instanceOwnershipDuration = TimeSpan.MaxValue;
TimeSpan loadingInterval = new TimeSpan(0, 2, 0);
SqlWorkflowPersistenceService persistService = new SqlWorkflowPersistenceService(connectionString, unloadOnIdle, instanceOwnershipDuration, loadingInterval);
// Add the SqlWorkflowPersistenceService to the runtime engine.
runtime.AddService( persistService );
}
}
The last bit we need to take care of is adding our startable component to the container which is pretty easy to do.
public class WorkflowFacility : AbstractFacility
{
protected override void Init()
{
Kernel.AddComponent(“workflow.defaultHost”, typeof(IStartable), typeof(WorkflowHost));
}
}
And the final piece is the configuration from the component
<facility
id=”workflow.facility”
type=”Seshat.Common.WorkflowFacility, Seshat.Common”
/>
That’s it :)
Then these guys would be a good place to start.
Please spread the word :)
http://www.seek.co.nz/jobsearch/index.ascx?DateRan…
I want somebody with almost no experience but a strong passion for the internet.
This person will have to move to New Plymouth.
If you know somebody please give them my details.
I don’t know how many of you know about this but I certainly didn’t
When you download the source of base4 which you can find here
And you navigate to the folder C:\Program Files\Base4 Solutions Ltd\Base4 version 2.1\Source**Base4.Storage\Resources**
Or whereever you installed the source and copy the xsd file that is there to the folder C:\Program Files\Microsoft Visual Studio 8**Xml\Schemas** (the folder xml schemas in your visual studio install dir)
When you restart/start visual studio now and you want to edit a schema now the things popup to assist you
Don’t forget to register on the base4 site if you haven’t already.
Enjoy


Garbage Collection with LLVM¶
- Abstract
- Quick Start
- Introduction
- LLVM IR Features
- Built In GC Strategies
- Custom GC Strategies
- Collector Requirements
- Implementing a collector plugin
- Overview of available features
- Computing stack maps
- Initializing roots to null:
InitRoots
- Custom lowering of intrinsics:
CustomRoots
,CustomReadBarriers
, andCustomWriteBarriers
- Generating safe points:
NeededSafePoints
- Emitting assembly code:
GCMetadataPrinter
- References
Abstract¶
This document covers how to integrate LLVM into a compiler for a language which supports garbage collection. Note that LLVM itself does not provide a garbage collector. You must provide your own.
Quick Start¶
First, you should pick a collector strategy. LLVM includes a number of built in ones, but you can also implement a loadable plugin with a custom definition. Note that the collector strategy is a description of how LLVM should generate code such that it interacts with your collector and runtime, not a description of the collector itself.
Next, mark your generated functions as using your chosen collector strategy. From c++, you can call:
F.setGC(<collector description name>);
This will produce IR like the following fragment:
define void @foo() gc "<collector description name>" { ... }
When generating LLVM IR for your functions, you will need to:
- Use
@llvm.gcread
<EMAIL_ADDRESS>in place of standard load and store instructions. These intrinsics are used to represent load and store barriers. If you collector does not require such barriers, you can skip this step. - Use the memory allocation routines provided by your garbage collector’s runtime library.
- If your collector requires them, generate type maps according to your runtime’s binary interface. LLVM is not involved in the process. In particular, the LLVM type system is not suitable for conveying such information though the compiler.
- Insert any coordination code required for interacting with your collector. Many collectors require running application code to periodically check a flag and conditionally call a runtime function. This is often referred to as a safepoint poll.
You will need to identify roots (i.e. references to heap objects your collector
needs to know about) in your generated IR, so that LLVM can encode them into
your final stack maps. Depending on the collector strategy chosen, this is
accomplished by using either the @llvm.gcroot
intrinsics or an
gc.statepoint
relocation sequence.
Don’t forget to create a root for each intermediate value that is generated when
evaluating an expression. In h(f(), g())
, the result of f()
could
easily be collected if evaluating g()
triggers a collection.
Finally, you need to link your runtime library with the generated program executable (for a static compiler) or ensure the appropriate symbols are available for the runtime linker (for a JIT compiler).
Introduction¶
What is Garbage Collection?¶
Garbage collection is a widely used technique that frees the programmer from having to know the lifetimes of heap objects, making software easier to produce and maintain. Many programming languages rely on garbage collection for automatic memory management. There are two primary forms of garbage collection: conservative and accurate.
Conservative garbage collection often does not require any special support from either the language or the compiler: it can handle non-type-safe programming languages (such as C/C++) and does not require any special information from the compiler. The Boehm collector is an example of a state-of-the-art conservative collector.
Accurate garbage collection requires the ability to identify all pointers in the program at run-time (which requires that the source-language be type-safe in most cases). Identifying pointers at run-time requires compiler support to locate all places that hold live pointer variables at run-time, including the processor stack and registers.
Conservative garbage collection is attractive because it does not require any special compiler support, but it does have problems. In particular, because the conservative garbage collector cannot know that a particular word in the machine is a pointer, it cannot move live objects in the heap (preventing the use of compacting and generational GC algorithms) and it can occasionally suffer from memory leaks due to integer values that happen to point to objects in the program. In addition, some aggressive compiler transformations can break conservative garbage collectors (though these seem rare in practice).
Accurate garbage collectors do not suffer from any of these problems, but they can suffer from degraded scalar optimization of the program. In particular, because the runtime must be able to identify and update all pointers active in the program, some optimizations are less effective. In practice, however, the locality and performance benefits of using aggressive garbage collection techniques dominates any low-level losses.
This document describes the mechanisms and interfaces provided by LLVM to support accurate garbage collection.
Goals and non-goals¶
LLVM’s intermediate representation provides garbage collection intrinsics that offer support for a broad class of collector models. For instance, the intrinsics permit:
- semi-space collectors
- mark-sweep collectors
- generational collectors
- incremental collectors
- concurrent collectors
- cooperative collectors
- reference counting
We hope that the support built into the LLVM IR is sufficient to support a broad class of garbage collected languages including Scheme, ML, Java, C#, Perl, Python, Lua, Ruby, other scripting languages, and more.
Note that LLVM does not itself provide a garbage collector — this should be part of your language’s runtime library. LLVM provides a framework for describing the garbage collectors requirements to the compiler. In particular, LLVM provides support for generating stack maps at call sites, polling for a safepoint, and emitting load and store barriers. You can also extend LLVM - possibly through a loadable code generation plugins - to generate code and data structures which conforms to the binary interface specified by the runtime library. This is similar to the relationship between LLVM and DWARF debugging info, for example. The difference primarily lies in the lack of an established standard in the domain of garbage collection — thus the need for a flexible extension mechanism.
The aspects of the binary interface with which LLVM’s GC support is concerned are:
- Creation of GC safepoints within code where collection is allowed to execute safely.
- Computation of the stack map. For each safe point in the code, object references within the stack frame must be identified so that the collector may traverse and perhaps update them.
- Write barriers when storing object references to the heap. These are commonly used to optimize incremental scans in generational collectors.
- Emission of read barriers when loading object references. These are useful for interoperating with concurrent collectors.
There are additional areas that LLVM does not directly address:
- Registration of global roots with the runtime.
- Registration of stack map entries with the runtime.
- The functions used by the program to allocate memory, trigger a collection, etc.
- Computation or compilation of type maps, or registration of them with the runtime. These are used to crawl the heap for object references.
In general, LLVM’s support for GC does not include features which can be adequately addressed with other features of the IR and does not specify a particular binary interface. On the plus side, this means that you should be able to integrate LLVM with an existing runtime. On the other hand, it can have the effect of leaving a lot of work for the developer of a novel language. We try to mitigate this by providing built in collector strategy descriptions that can work with many common collector designs and easy extension points. If you don’t already have a specific binary interface you need to support, we recommend trying to use one of these built in collector strategies.
LLVM IR Features¶
This section describes the garbage collection facilities provided by the LLVM intermediate representation. The exact behavior of these IR features is specified by the selected GC strategy description.
Specifying GC code generation: gc "..."
¶
define <returntype> @name(...) gc "name" { ... }
The gc
function attribute is used to specify the desired GC strategy to the
compiler. Its programmatic equivalent is the setGC
method of Function
.
Setting gc "name"
on a function triggers a search for a matching subclass
of GCStrategy. Some collector strategies are built in. You can add others
using either the loadable plugin mechanism, or by patching your copy of LLVM.
It is the selected GC strategy which defines the exact nature of the code
generated to support GC. If none is found, the compiler will raise an error.
Specifying the GC style on a per-function basis allows LLVM to link together programs that use different garbage collection algorithms (or none at all).
Identifying GC roots on the stack¶
LLVM currently supports two different mechanisms for describing references in
compiled code at safepoints. llvm.gcroot
is the older mechanism;
gc.statepoint
has been added more recently. At the moment, you can choose
either implementation (on a per GC strategy basis). Longer
term, we will probably either migrate away from llvm.gcroot
entirely, or
substantially merge their implementations. Note that most new development
work is focused on gc.statepoint
.
Using gc.statepoint
¶
This page contains detailed documentation for
gc.statepoint
.
Using llvm.gcwrite
¶
void @llvm.gcroot(i8** %ptrloc, i8* %metadata)
The llvm.gcroot
intrinsic is used to inform LLVM that a stack variable
references an object on the heap and is to be tracked for garbage collection.
The exact impact on generated code is specified by the Function’s selected
GC strategy. All calls to llvm.gcroot
must reside
inside the first basic block.
The first argument must be a value referring to an alloca instruction or a bitcast of an alloca. The second contains a pointer to metadata that should be associated with the pointer, and must be a constant or global value address. If your target collector uses tags, use a null pointer for metadata.
A compiler which performs manual SSA construction must ensure that SSA
values representing GC references are stored in to the alloca passed to the
respective gcroot
before every call site and reloaded after every call.
A compiler which uses mem2reg to raise imperative code using alloca
into
SSA form need only add a call to @llvm.gcroot
for those variables which
are pointers into the GC heap.
It is also important to mark intermediate values with llvm.gcroot
. For
example, consider h(f(), g())
. Beware leaking the result of f()
in the
case that g()
triggers a collection. Note, that stack variables must be
initialized and marked with llvm.gcroot
in function’s prologue.
The %metadata
argument can be used to avoid requiring heap objects to have
‘isa’ pointers or tag bits. [Appel89, Goldberg91, Tolmach94] If specified,
its value will be tracked along with the location of the pointer in the stack
frame.
Consider the following fragment of Java code:
{
Object X; // A null-initialized reference to an object
...
}
This block (which may be located in the middle of a function or in a loop nest), could be compiled to this LLVM code:
Entry:
;; In the entry block for the function, allocate the
;; stack space for X, which is an LLVM pointer.
%X = alloca %Object*
;; Tell LLVM that the stack space is a stack root.
;; Java has type-tags on objects, so we pass null as metadata.
%tmp = bitcast %Object** %X to i8**
call void @llvm.gcroot(i8** %tmp, i8* null)
...
;; "CodeBlock" is the block corresponding to the start
;; of the scope above.
CodeBlock:
;; Java null-initializes pointers.
store %Object* null, %Object** %X
...
;; As the pointer goes out of scope, store a null value into
;; it, to indicate that the value is no longer live.
store %Object* null, %Object** %X
...
Reading and writing references in the heap¶
Some collectors need to be informed when the mutator (the program that needs garbage collection) either reads a pointer from or writes a pointer to a field of a heap object. The code fragments inserted at these points are called read barriers and write barriers, respectively. The amount of code that needs to be executed is usually quite small and not on the critical path of any computation, so the overall performance impact of the barrier is tolerable.
Barriers often require access to the object pointer rather than the derived
pointer (which is a pointer to the field within the object). Accordingly,
these intrinsics take both pointers as separate arguments for completeness. In
this snippet, %object
is the object pointer, and %derived
is the derived
pointer:
;; An array type.
%class.Array = type { %class.Object, i32, [0 x %class.Object*] }
...
;; Load the object pointer from a gcroot.
%object = load %class.Array** %object_addr
;; Compute the derived pointer.
%derived = getelementptr %object, i32 0, i32 2, i32 %n
LLVM does not enforce this relationship between the object and derived pointer (although a particular collector strategy might). However, it would be an unusual collector that violated it.
The use of these intrinsics is naturally optional if the target GC does not
require the corresponding barrier. The GC strategy used with such a collector
should replace the intrinsic calls with the corresponding load
or
store
instruction if they are used.
One known deficiency with the current design is that the barrier intrinsics do not include the size or alignment of the underlying operation performed. It is currently assumed that the operation is of pointer size and the alignment is assumed to be the target machine’s default alignment.
Write barrier: llvm.gcwrite
¶
void @llvm.gcwrite(i8* %value, i8* %object, i8** %derived)
For write barriers, LLVM provides the llvm.gcwrite
intrinsic function. It
has exactly the same semantics as a non-volatile store
to the derived
pointer (the third argument). The exact code generated is specified by the
Function’s selected GC strategy.
Many important algorithms require write barriers, including generational and concurrent collectors. Additionally, write barriers could be used to implement reference counting.
Read barrier: llvm.gcread
¶
i8* @llvm.gcread(i8* %object, i8** %derived)
For read barriers, LLVM provides the llvm.gcread
intrinsic function. It has
exactly the same semantics as a non-volatile load
from the derived pointer
(the second argument). The exact code generated is specified by the Function’s
selected GC strategy.
Read barriers are needed by fewer algorithms than write barriers, and may have a greater performance impact since pointer reads are more frequent than writes.
Built In GC Strategies¶
LLVM includes built in support for several varieties of garbage collectors.
The Shadow Stack GC¶
To use this collector strategy, mark your functions with:
F.setGC("shadow-stack");
Unlike many GC algorithms which rely on a cooperative code generator to compile stack maps, this algorithm carefully maintains a linked list of stack roots [Henderson2002]. This so-called “shadow stack” mirrors the machine stack. Maintaining this data structure is slower than using a stack map compiled into the executable as constant data, but has a significant portability advantage because it requires no special support from the target code generator, and does not require tricky platform-specific code to crawl the machine stack.
The tradeoff for this simplicity and portability is:
- High overhead per function call.
- Not thread-safe.
Still, it’s an easy way to get started. After your compiler and runtime are up and running, writing a plugin will allow you to take advantage of more advanced GC features of LLVM in order to improve performance.
The shadow stack doesn’t imply a memory allocation algorithm. A semispace
collector or building atop malloc
are great places to start, and can be
implemented with very little code.
When it comes time to collect, however, your runtime needs to traverse the stack roots, and for this it needs to integrate with the shadow stack. Luckily, doing so is very simple. (This code is heavily commented to help you understand the data structure, but there are only 20 lines of meaningful code.)
/// @brief The map for a single function's stack frame. One of these is
/// compiled as constant data into the executable for each function.
///
/// Storage of metadata values is elided if the %metadata parameter to
/// @llvm.gcroot is null.
struct FrameMap {
int32_t NumRoots; //< Number of roots in stack frame.
int32_t NumMeta; //< Number of metadata entries. May be < NumRoots.
const void *Meta[0]; //< Metadata for each root.
};
/// @brief A link in the dynamic shadow stack. One of these is embedded in
/// the stack frame of each function on the call stack.
struct StackEntry {
StackEntry *Next; //< Link to next stack entry (the caller's).
const FrameMap *Map; //< Pointer to constant FrameMap.
void *Roots[0]; //< Stack roots (in-place array).
};
/// @brief The head of the singly-linked list of StackEntries. Functions push
/// and pop onto this in their prologue and epilogue.
///
/// Since there is only a global list, this technique is not threadsafe.
StackEntry *llvm_gc_root_chain;
/// @brief Calls Visitor(root, meta) for each GC root on the stack.
/// root and meta are exactly the values passed to
/// @llvm.gcroot.
///
/// Visitor could be a function to recursively mark live objects. Or it
/// might copy them to another heap or generation.
///
/// @param Visitor A function to invoke for every GC root on the stack.
void visitGCRoots(void (*Visitor)(void **Root, const void *Meta)) {
for (StackEntry *R = llvm_gc_root_chain; R; R = R->Next) {
unsigned i = 0;
// For roots [0, NumMeta), the metadata pointer is in the FrameMap.
for (unsigned e = R->Map->NumMeta; i != e; ++i)
Visitor(&R->Roots[i], R->Map->Meta[i]);
// For roots [NumMeta, NumRoots), the metadata pointer is null.
for (unsigned e = R->Map->NumRoots; i != e; ++i)
Visitor(&R->Roots[i], NULL);
}
}
The ‘Erlang’ and ‘Ocaml’ GCs¶
LLVM ships with two example collectors which leverage the gcroot
mechanisms. To our knowledge, these are not actually used by any language
runtime, but they do provide a reasonable starting point for someone interested
in writing an gcroot
compatible GC plugin. In particular, these are the
only in tree examples of how to produce a custom binary stack map format using
a gcroot
strategy.
As there names imply, the binary format produced is intended to model that used by the Erlang and OCaml compilers respectively.
The Statepoint Example GC¶
F.setGC("statepoint-example");
This GC provides an example of how one might use the infrastructure provided
by gc.statepoint
. This example GC is compatible with the
PlaceSafepoints and RewriteStatepointsForGC utility passes
which simplify gc.statepoint
sequence insertion. If you need to build a
custom GC strategy around the gc.statepoints
mechanisms, it is recommended
that you use this one as a starting point.
This GC strategy does not support read or write barriers. As a result, these intrinsics are lowered to normal loads and stores.
The stack map format generated by this GC strategy can be found in the Stack Map Section using a format documented here. This format is intended to be the standard format supported by LLVM going forward.
The CoreCLR GC¶
F.setGC("coreclr");
This GC leverages the gc.statepoint
mechanism to support the
CoreCLR runtime.
Support for this GC strategy is a work in progress. This strategy will differ from statepoint-example GC strategy in certain aspects like:
- Base-pointers of interior pointers are not explicitly tracked and reported.
- A different format is used for encoding stack maps.
- Safe-point polls are only needed before loop-back edges and before tail-calls (not needed at function-entry).
Custom GC Strategies¶
If none of the built in GC strategy descriptions met your needs above, you will need to define a custom GCStrategy and possibly, a custom LLVM pass to perform lowering. Your best example of where to start defining a custom GCStrategy would be to look at one of the built in strategies.
You may be able to structure this additional code as a loadable plugin library. Loadable plugins are sufficient if all you need is to enable a different combination of built in functionality, but if you need to provide a custom lowering pass, you will need to build a patched version of LLVM. If you think you need a patched build, please ask for advice on llvm-dev. There may be an easy way we can extend the support to make it work for your use case without requiring a custom build.
Collector Requirements¶
You should be able to leverage any existing collector library that includes the following elements:
- A memory allocator which exposes an allocation function your compiled code can call.
- A binary format for the stack map. A stack map describes the location of references at a safepoint and is used by precise collectors to identify references within a stack frame on the machine stack. Note that collectors which conservatively scan the stack don’t require such a structure.
- A stack crawler to discover functions on the call stack, and enumerate the references listed in the stack map for each call site.
- A mechanism for identifying references in global locations (e.g. global variables).
- If you collector requires them, an LLVM IR implementation of your collectors load and store barriers. Note that since many collectors don’t require barriers at all, LLVM defaults to lowering such barriers to normal loads and stores unless you arrange otherwise.
Implementing a collector plugin¶
User code specifies which GC code generation to use with the gc
function
attribute or, equivalently, with the setGC
method of Function
.
To implement a GC plugin, it is necessary to subclass llvm::GCStrategy
,
which can be accomplished in a few lines of boilerplate code. LLVM’s
infrastructure provides access to several important algorithms. For an
uncontroversial collector, all that remains may be to compile LLVM’s computed
stack map to assembly code (using the binary representation expected by the
runtime library). This can be accomplished in about 100 lines of code.
 That code should exist in the language’s runtime library. The compiler plugin is responsible for generating code which conforms to the binary interface defined by library, most essentially the stack map.
To subclass llvm::GCStrategy
and register it with the compiler:
// lib/MyGC/MyGC.cpp - Example LLVM GC plugin
#include "llvm/CodeGen/GCStrategy.h"
#include "llvm/CodeGen/GCMetadata.h"
#include "llvm/Support/Compiler.h"
using namespace llvm;
namespace {
class LLVM_LIBRARY_VISIBILITY MyGC : public GCStrategy {
public:
MyGC() {}
};
GCRegistry::Add<MyGC>
X("mygc", "My bespoke garbage collector.");
}
This boilerplate collector does nothing. More specifically:
llvm.gcread
calls are replaced with the correspondingload
instruction.llvm.gcwrite
calls are replaced with the correspondingstore
instruction.- No safe points are added to the code.
- The stack map is not compiled into the executable.
Using the LLVM makefiles, this code can be compiled as a plugin using a simple makefile:
# lib/MyGC/Makefile
LEVEL := ../..
LIBRARYNAME = MyGC
LOADABLE_MODULE = 1
include $(LEVEL)/Makefile.common
Once the plugin is compiled, code using it may be compiled using llc
-load=MyGC.so
(though MyGC.so may have some other platform-specific
extension):
$ cat sample.ll
define void @f() gc "mygc" {
entry:
ret void
}
$ llvm-as < sample.ll | llc -load=MyGC.so
It is also possible to statically link the collector plugin into tools, such as a language-specific compiler front-end.
Overview of available features¶
GCStrategy
provides a range of features through which a plugin may do useful
work. Some of these are callbacks, some are algorithms that can be enabled,
disabled, or customized. This matrix summarizes the supported (and planned)
features and correlates them with the collection techniques which typically
require them.
| Algorithm | Done | Shadow stack | refcount | mark- sweep | copying | incremental | threaded | concurrent |
|---|---|---|---|---|---|---|---|---|
| stack map | ✔ | ✘ | ✘ | ✘ | ✘ | ✘ | ||
| initialize roots | ✔ | ✘ | ✘ | ✘ | ✘ | ✘ | ✘ | ✘ |
| derived pointers | NO | N* | N* | |||||
| custom lowering | ✔ | |||||||
| gcroot | ✔ | ✘ | ✘ | |||||
| gcwrite | ✔ | ✘ | ✘ | ✘ | ||||
| gcread | ✔ | ✘ | ||||||
| safe points | ||||||||
| in calls | ✔ | ✘ | ✘ | ✘ | ✘ | ✘ | ||
| before calls | ✔ | ✘ | ✘ | |||||
| for loops | NO | N | N | |||||
| before escape | ✔ | ✘ | ✘ | |||||
| emit code at safe points | NO | N | N | |||||
| output | ||||||||
| assembly | ✔ | ✘ | ✘ | ✘ | ✘ | ✘ | ||
| JIT | NO | ? | ? | ? | ? | ? | ||
| obj | NO | ? | ? | ? | ? | ? | ||
| live analysis | NO | ? | ? | ? | ? | ? | ||
| register map | NO | ? | ? | ? | ? | ? | ||
| * Derived pointers only pose a hasard to copying collections. | ||||||||
| ? denotes a feature which could be utilized if available. |
To be clear, the collection techniques above are defined as:
- Shadow Stack
- The mutator carefully maintains a linked list of stack roots.
- Reference Counting
- The mutator maintains a reference count for each object and frees an object when its count falls to zero.
- Mark-Sweep
- When the heap is exhausted, the collector marks reachable objects starting from the roots, then deallocates unreachable objects in a sweep phase.
- Copying
- As reachability analysis proceeds, the collector copies objects from one heap area to another, compacting them in the process. Copying collectors enable highly efficient “bump pointer” allocation and can improve locality of reference.
- Incremental
- (Including generational collectors.) Incremental collectors generally have all the properties of a copying collector (regardless of whether the mature heap is compacting), but bring the added complexity of requiring write barriers.
- Threaded
- Denotes a multithreaded mutator; the collector must still stop the mutator (“stop the world”) before beginning reachability analysis. Stopping a multithreaded mutator is a complicated problem. It generally requires highly platform-specific code in the runtime, and the production of carefully designed machine code at safe points.
- Concurrent
- In this technique, the mutator and the collector run concurrently, with the goal of eliminating pause times. In a cooperative collector, the mutator further aids with collection should a pause occur, allowing collection to take advantage of multiprocessor hosts. The “stop the world” problem of threaded collectors is generally still present to a limited extent. Sophisticated marking algorithms are necessary. Read barriers may be necessary.
As the matrix indicates, LLVM’s garbage collection infrastructure is already suitable for a wide variety of collectors, but does not currently extend to multithreaded programs. This will be added in the future as there is interest.
Computing stack maps¶
LLVM automatically computes a stack map. One of the most important features
of a GCStrategy
is to compile this information into the executable in
the binary representation expected by the runtime library.
The stack map consists of the location and identity of each GC root in the each function in the module. For each root:
RootNum
: The index of the root.StackOffset
: The offset of the object relative to the frame pointer.RootMetadata
: The value passed as the%metadata
parameter to<EMAIL_ADDRESS>intrinsic.
Also, for the function as a whole:
getFrameSize()
: The overall size of the function’s initial stack frame,- not accounting for any dynamic allocation.
roots_size()
: The count of roots in the function.
To access the stack map, use GCFunctionMetadata::roots_begin()
and
-end()
from the GCMetadataPrinter:
for (iterator I = begin(), E = end(); I != E; ++I) {
GCFunctionInfo *FI = *I;
unsigned FrameSize = FI->getFrameSize();
size_t RootCount = FI->roots_size();
for (GCFunctionInfo::roots_iterator RI = FI->roots_begin(),
RE = FI->roots_end();
RI != RE; ++RI) {
int RootNum = RI->Num;
int RootStackOffset = RI->StackOffset;
Constant *RootMetadata = RI->Metadata;
}
}
If the llvm.gcroot
intrinsic is eliminated before code generation by a
custom lowering pass, LLVM will compute an empty stack map. This may be useful
for collector plugins which implement reference counting or a shadow stack.
Initializing roots to null: InitRoots
¶
MyGC::MyGC() {
InitRoots = true;
}
When set, LLVM will automatically initialize each root to null
upon entry to
the function. This prevents the GC’s sweep phase from visiting uninitialized
pointers, which will almost certainly cause it to crash. This initialization
occurs before custom lowering, so the two may be used together.
Since LLVM does not yet compute liveness information, there is no means of distinguishing an uninitialized stack root from an initialized one. Therefore, this feature should be used by all GC plugins. It is enabled by default.
Custom lowering of intrinsics: CustomRoots
, CustomReadBarriers
, and CustomWriteBarriers
¶
For GCs which use barriers or unusual treatment of stack roots, these flags allow the collector to perform arbitrary transformations of the LLVM IR:
class MyGC : public GCStrategy {
public:
MyGC() {
CustomRoots = true;
CustomReadBarriers = true;
CustomWriteBarriers = true;
}
};
If any of these flags are set, LLVM suppresses its default lowering for the corresponding intrinsics. Instead, you must provide a custom Pass which lowers the intrinsics as desired. If you have opted in to custom lowering of a particular intrinsic your pass must eliminate all instances of the corresponding intrinsic in functions which opt in to your GC. The best example of such a pass is the ShadowStackGC and it’s ShadowStackGCLowering pass.
There is currently no way to register such a custom lowering pass without building a custom copy of LLVM.
Generating safe points: NeededSafePoints
¶
LLVM can compute four kinds of safe points:
namespace GC {
/// PointKind - The type of a collector-safe point.
///
enum PointKind {
Loop, //< Instr is a loop (backwards branch).
Return, //< Instr is a return instruction.
PreCall, //< Instr is a call instruction.
PostCall //< Instr is the return address of a call.
};
}
A collector can request any combination of the four by setting the
NeededSafePoints
mask:
MyGC::MyGC() {
NeededSafePoints = 1 << GC::Loop
| 1 << GC::Return
| 1 << GC::PreCall
| 1 << GC::PostCall;
}
It can then use the following routines to access safe points.
for (iterator I = begin(), E = end(); I != E; ++I) {
GCFunctionInfo *MD = *I;
size_t PointCount = MD->size();
for (GCFunctionInfo::iterator PI = MD->begin(),
PE = MD->end(); PI != PE; ++PI) {
GC::PointKind PointKind = PI->Kind;
unsigned PointNum = PI->Num;
}
}
Almost every collector requires PostCall
safe points, since these correspond
to the moments when the function is suspended during a call to a subroutine.
Threaded programs generally require Loop
safe points to guarantee that the
application will reach a safe point within a bounded amount of time, even if it
is executing a long-running loop which contains no function calls.
Threaded collectors may also require Return
and PreCall
safe points to
implement “stop the world” techniques using self-modifying code, where it is
important that the program not exit the function without reaching a safe point
(because only the topmost function has been patched).
Emitting assembly code: GCMetadataPrinter
¶
LLVM allows a plugin to print arbitrary assembly code before and after the rest of a module’s assembly code. At the end of the module, the GC can compile the LLVM stack map into assembly code. (At the beginning, this information is not yet computed.)
Since AsmWriter and CodeGen are separate components of LLVM, a separate abstract
base class and registry is provided for printing assembly code, the
GCMetadaPrinter
and GCMetadataPrinterRegistry
. The AsmWriter will look
for such a subclass if the GCStrategy
sets UsesMetadata
:
MyGC::MyGC() {
UsesMetadata = true;
}
This separation allows JIT-only clients to be smaller.
Note that LLVM does not currently have analogous APIs to support code generation in the JIT, nor using the object writers.
// lib/MyGC/MyGCPrinter.cpp - Example LLVM GC printer
#include "llvm/CodeGen/GCMetadataPrinter.h"
#include "llvm/Support/Compiler.h"
using namespace llvm;
namespace {
class LLVM_LIBRARY_VISIBILITY MyGCPrinter : public GCMetadataPrinter {
public:
virtual void beginAssembly(AsmPrinter &AP);
virtual void finishAssembly(AsmPrinter &AP);
};
GCMetadataPrinterRegistry::Add<MyGCPrinter>
X("mygc", "My bespoke garbage collector.");
}
The collector should use AsmPrinter
to print portable assembly code. The
collector itself contains the stack map for the entire module, and may access
the GCFunctionInfo
using its own begin()
and end()
methods. Here’s
a realistic example:
#include "llvm/CodeGen/AsmPrinter.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/Target/TargetAsmInfo.h"
#include "llvm/Target/TargetMachine.h"
void MyGCPrinter::beginAssembly(AsmPrinter &AP) {
// Nothing to do.
}
void MyGCPrinter::finishAssembly(AsmPrinter &AP) {
MCStreamer &OS = AP.OutStreamer;
unsigned IntPtrSize = AP.getPointerSize();
// Put this in the data section.
OS.SwitchSection(AP.getObjFileLowering().getDataSection());
// For each function...
for (iterator FI = begin(), FE = end(); FI != FE; ++FI) {
GCFunctionInfo &MD = **FI;
// A compact GC layout. Emit this data structure:
//
// struct {
// int32_t PointCount;
// void *SafePointAddress[PointCount];
// int32_t StackFrameSize; // in words
// int32_t StackArity;
// int32_t LiveCount;
// int32_t LiveOffsets[LiveCount];
// } __gcmap_<FUNCTIONNAME>;
// Align to address width.
AP.EmitAlignment(IntPtrSize == 4 ? 2 : 3);
// Emit PointCount.
OS.AddComment("safe point count");
AP.EmitInt32(MD.size());
// And each safe point...
for (GCFunctionInfo::iterator PI = MD.begin(),
PE = MD.end(); PI != PE; ++PI) {
// Emit the address of the safe point.
OS.AddComment("safe point address");
MCSymbol *Label = PI->Label;
AP.EmitLabelPlusOffset(Label/*Hi*/, 0/*Offset*/, 4/*Size*/);
}
// Stack information never change in safe points! Only print info from the
// first call-site.
GCFunctionInfo::iterator PI = MD.begin();
// Emit the stack frame size.
OS.AddComment("stack frame size (in words)");
AP.EmitInt32(MD.getFrameSize() / IntPtrSize);
// Emit stack arity, i.e. the number of stacked arguments.
unsigned RegisteredArgs = IntPtrSize == 4 ? 5 : 6;
unsigned StackArity = MD.getFunction().arg_size() > RegisteredArgs ?
MD.getFunction().arg_size() - RegisteredArgs : 0;
OS.AddComment("stack arity");
AP.EmitInt32(StackArity);
// Emit the number of live roots in the function.
OS.AddComment("live root count");
AP.EmitInt32(MD.live_size(PI));
// And for each live root...
for (GCFunctionInfo::live_iterator LI = MD.live_begin(PI),
LE = MD.live_end(PI);
LI != LE; ++LI) {
// Emit live root's offset within the stack frame.
OS.AddComment("stack index (offset / wordsize)");
AP.EmitInt32(LI->StackOffset);
}
}
}
References¶
[Appel89] Runtime Tags Aren’t Necessary. Andrew W. Appel. Lisp and Symbolic Computation 19(7):703-705, July 1989.
[Goldberg91] Tag-free garbage collection for strongly typed programming languages. Benjamin Goldberg. ACM SIGPLAN PLDI‘91.
[Tolmach94] Tag-free garbage collection using explicit type parameters. Andrew Tolmach. Proceedings of the 1994 ACM conference on LISP and functional programming.
[Henderson2002] Accurate Garbage Collection in an Uncooperative Environment


Patiend ID:
Height: Weight:
1: 2: 3: 4: 5: 6:
Upper: Lower:
Breakfast 1: 2: 3: Lunch 1: 2: 3: Dinner 1: 2: 3:
Foot ball Hockey Cricket Chess All None
Tourism
Writing
Disease Name:
Signature With Date:
Doctor ID:
Doctor Name:
Submit form


I’m a final-year student pursuing B.Tech from Jamia Millia Islamia in Electronic and Communication. Currently doing research internship at IIITD.
I have a major interest in programming and problem-solving. I
have good knowledge of Machine Learning (And AI) and am interested in Research in ML or DL domains. I have done a good amount of projects (Listed Below) to support my skills. I also have good knowledge and experience in Web development (Both FrontEnd and Backend).
B.Tech in Electronics and Communication, 2021
Jamia Millia Islamia
Senior School Certificate Examination(Class 12), 2016
Dev Samaj Modern Schoo
Catalytic production of high-value chemicals from high volume non-food biomass: Implications from Machine learning in acid catalysis
with Md. Imteyaz Alam which is going to be published soon by Springer Nature
.Ground transport and logistics solution company based in Germany


Home
Quick Links
G+
Wiki
Scholar
Wiktionary
Snopes
Internal Pages
News
Tech
Make
Think
Read
Music
Media
Food


| Customer Name : | Md. Afzalur Rashid |
|---|---|
| Wallet Type : | Customer |
| Operator : | Not found |
| Date of Birth : | 01/08/1980 |
| Customer App Version : | ---- |
| Suspension Status : | Not Suspended |
| Verification Date : | 4/22/2021 |
| Wallet ID : |<PHONE_NUMBER>6 |
|---|---|
| Email : |<EMAIL_ADDRESS>|
| Gender : | M |
| National ID : |<PHONE_NUMBER>445 |
| Wallet Status : | Active |
| Current Balance : | 12513.61 |
Personal Information
| Father Name : | --- |
|---|---|
| Device Name : | Customer |
| Permanent Address : | --- |
| Occupation : | --- |
| Customer App Version : | ---- |
| Transaction Purpose : | --- |
| NID Status : | --- |
| Email Status | --- |
| Registration Date : | --- |
| Mother Name : | --- |
|---|---|
| Authorized Person Name: | ---- |
| Present Address : | ---- |
| Source of Income : | ---- |
| Profile Picture Status | ----- |
| Bank Information Status : | 12513.61 |
| No of Devices : | --- |
Bank Information
| Bank name | Type | District name | Branch Name | Bank A/C Name | Bank A/C Number | A/c Addition Date | A/c Removal Date | Status |
|---|---|---|---|---|---|---|---|---|
| Verified |
Transactional Information
| Txn Ref ID | Txn Date | Txn Time | Payer | Payer Mobile/AC No. | Payee Name | Payee Mobile/AC No. | Cluster | Transaction Type | Credit | Debit | Fee | Particulars |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| B06C02A4033B | 5/11/2021 | 3:09:42 PM | Md. Afzalur Rashid |<PHONE_NUMBER>6 | LankaBangla Credit Card |<PHONE_NUMBER>4 | DM | Bill Pay | Tk 0 | Tk 12000 | Tk 0 | IcBillPay. Bank name :AL-ARAFAH ISLAMI BANK LTD. Bank account number :99212******15 TRACKING NO.<PHONE_NUMBER>6-1UKCQFUHFFQSEUMT. Dmoney Transaction Reference : B0737952B86C Channel : IOS_APP & App Version : 2.4.1 |
Transactional Information
| Txn Ref ID | Txn Date | Txn Time | Payer | Payer Mobile/AC No. | Payee Name | Payee Mobile/AC No. | Cluster | Transaction Type | Credit | Debit | Fee | Particulars |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| B06C02A4033B | 5/11/2021 | 3:09:42 PM | Md. Afzalur Rashid |<PHONE_NUMBER>6 | LankaBangla Credit Card |<PHONE_NUMBER>4 | DM | Bill Pay | Tk 0 | Tk 12000 | Tk 0 | IcBillPay. Bank name :AL-ARAFAH ISLAMI BANK LTD. Bank account number :99212******15 TRACKING NO.<PHONE_NUMBER>6-1UKCQFUHFFQSEUMT. Dmoney Transaction Reference : B0737952B86C Channel : IOS_APP & App Version : 2.4.1 |
Used Limit
| Transaction Category | Service Code | Daily Limit | Weekly Limit | Monthly Limit | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Count | Amount | Count | Amount | Count | Amount | ||||||||
| Maximum | Used | Maximum | Used | Maximum | Used | Maximum | Used | Maximum | Used | Maximum | Used | ||


Community risks for fire departments were determined via statistical regression models that predict various types of risk as a function of community attributes. Five community risks were assessed through the statistical modelling exercise:
Community risks were estimated as a function of the socio-demographic and geographic characteristics of the locations (census tracts) of residential fires over a 9 year period (2014-2012) according to NFIRS data. The socio-demographic attributes to help predict risk included such items as:
Models were separately calculated for groups of departments with similar protected population size and region. (Departments serving fewer than 10,000 people were excluded from the analysis.) One exception is that departments serving 1 million or more people were analyzed as a single group regardless of region. Separate models were computed for 24 department size × region combinations. Specific notes about individual groups of regressions follow: Fire size models predicting the proportions of fires that fit into each size category as well as models predicting deaths and injuries represent an overall ‘average’ department (i.e., the models do not include a department specific ‘effect’). Also, note that because deaths are rare, many departments will be predicted to have only a fractional number of deaths.


TutorJS Examples
Hello, World!
Basic Usage
Check out the sidebar for examples using TutorJS. More coming soon.
Basic Usage
Event Handling
AJAX & options.wait
Made by pxljoy.io


This referral does not require charity care.
For Breast Ultrasounds, click here. For Carotid Ultrasounds click here.
When calling IMA, make sure to have: the patient’s name, MRN, specific ultrasound test, and the next time they will be seen at EHHOP. Ideally, the appointment should be made before the patient’s next visit to EHHOP. Make sure to ask for specific instructions. Generally, those are:
Unless otherwise mentioned, ultrasounds take place in CAM building (same building as EHHOP), 17 E 102nd St, at end of hallway on sixth floor.
Cost to EHHOP Patient: Free.
~2 weeks
IMA Radiology, 6th floor CAM building, 17 East 102nd St<PHONE_NUMBER>
Appointment hours: Very flexible through the week.
EHHOP Ultrasound Rep: Alexander Rosen


EARLE.
....
I9O7
Legend -
Level of confidence that token is an accurately-transcribed word
extremely low
very low
low
undetermined
medium
high
very high


Health-e News Medicine Stockout Reporting Download Stockout Reports {% for start_date, end_date in weeks %} {{ start_date|date:"j F Y" }} - {{ end_date|date:"j F Y" }} {% endfor %}


EBD - Easton Bible DIctionary
Bartimaeus
BARTIMAEUS
"BARTIMAEUS "son of Timaeus, one of the two blind beggars of Jericho(
Mark 10:46
;
Matthew 20:30
). His blindness was miraculously cured on the ground of his faith.
"BARTIMAEUS "son of Timaeus, one of the two blind beggars of Jericho(Mark 10:46; Matthew 20:30). His blindness was miraculously cured on the ground of his faith.


< prev index next > modules/javafx.web/src/main/native/Source/ThirdParty/libxml/src/aclocal.m4
Print this page
You have another version of autoconf. It may work, but is not guaranteed to.
If you have problems, you may need to regenerate the build system entirely.
To do so, use the procedure documented by the package, typically 'autoreconf'.])])
# pkg.m4 - Macros to locate and utilise pkg-config. -*- Autoconf -*-
! # serial 12 (pkg-config-0.29.2)
dnl Copyright © 2004 Scott James Remnant<EMAIL_ADDRESS>dnl Copyright © 2012-2015 Dan Nicholson<EMAIL_ADDRESS>dnl
dnl This program is free software; you can redistribute it and/or modify
You have another version of autoconf. It may work, but is not guaranteed to.
If you have problems, you may need to regenerate the build system entirely.
To do so, use the procedure documented by the package, typically 'autoreconf'.])])
# pkg.m4 - Macros to locate and utilise pkg-config. -*- Autoconf -*-
! # serial 11 (pkg-config-0.29.1)
dnl Copyright © 2004 Scott James Remnant<EMAIL_ADDRESS>dnl Copyright © 2012-2015 Dan Nicholson<EMAIL_ADDRESS>dnl
dnl This program is free software; you can redistribute it and/or modify
dnl [m4_fatal([must install pkg-config 0.29 or later before running autoconf/autogen])])
dnl
dnl See the "Since" comment for each macro you use to see what version
dnl of the macros you require.
m4_defun([PKG_PREREQ],
! [m4_define([PKG_MACROS_VERSION], [0.29.2])
m4_if(m4_version_compare(PKG_MACROS_VERSION, [$1]), -1,
[m4_fatal([pkg.m4 version $1 or higher is required but ]PKG_MACROS_VERSION[ found])])
])dnl PKG_PREREQ
dnl PKG_PROG_PKG_CONFIG([MIN-VERSION])
dnl [m4_fatal([must install pkg-config 0.29 or later before running autoconf/autogen])])
dnl
dnl See the "Since" comment for each macro you use to see what version
dnl of the macros you require.
m4_defun([PKG_PREREQ],
! [m4_define([PKG_MACROS_VERSION], [0.29.1])
m4_if(m4_version_compare(PKG_MACROS_VERSION, [$1]), -1,
[m4_fatal([pkg.m4 version $1 or higher is required but ]PKG_MACROS_VERSION[ found])])
])dnl PKG_PREREQ
dnl PKG_PROG_PKG_CONFIG([MIN-VERSION])
[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl
AC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl
pkg_failed=no
! AC_MSG_CHECKING([for $2])
_PKG_CONFIG([$1][_CFLAGS], [cflags], [$2])
_PKG_CONFIG([$1][_LIBS], [libs], [$2])
m4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS
[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl
AC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl
pkg_failed=no
! AC_MSG_CHECKING([for $1])
_PKG_CONFIG([$1][_CFLAGS], [cflags], [$2])
_PKG_CONFIG([$1][_LIBS], [libs], [$2])
m4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS
AS_VAR_COPY([$1], [pkg_cv_][$1])
AS_VAR_IF([$1], [""], [$5], [$4])dnl
])dnl PKG_CHECK_VAR
+ dnl PKG_WITH_MODULES(VARIABLE-PREFIX, MODULES,
+ dnl [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND],
+ dnl [DESCRIPTION], [DEFAULT])
+ dnl ------------------------------------------
+ dnl
+ dnl Prepare a "--with-" configure option using the lowercase
+ dnl [VARIABLE-PREFIX] name, merging the behaviour of AC_ARG_WITH and
+ dnl PKG_CHECK_MODULES in a single macro.
+ AC_DEFUN([PKG_WITH_MODULES],
+ [
+ m4_pushdef([with_arg], m4_tolower([$1]))
+
+ m4_pushdef([description],
+ [m4_default([$5], [build with ]with_arg[ support])])
+
+ m4_pushdef([def_arg], [m4_default([$6], [auto])])
+ m4_pushdef([def_action_if_found], [AS_TR_SH([with_]with_arg)=yes])
+ m4_pushdef([def_action_if_not_found], [AS_TR_SH([with_]with_arg)=no])
+
+ m4_case(def_arg,
+ [yes],[m4_pushdef([with_without], [--without-]with_arg)],
+ [m4_pushdef([with_without],[--with-]with_arg)])
+
+ AC_ARG_WITH(with_arg,
+ AS_HELP_STRING(with_without, description[ @<:@default=]def_arg[@:>@]),,
+ [AS_TR_SH([with_]with_arg)=def_arg])
+
+ AS_CASE([$AS_TR_SH([with_]with_arg)],
+ [yes],[PKG_CHECK_MODULES([$1],[$2],$3,$4)],
+ [auto],[PKG_CHECK_MODULES([$1],[$2],
+ [m4_n([def_action_if_found]) $3],
+ [m4_n([def_action_if_not_found]) $4])])
+
+ m4_popdef([with_arg])
+ m4_popdef([description])
+ m4_popdef([def_arg])
+
+ ])dnl PKG_WITH_MODULES
+
+ dnl PKG_HAVE_WITH_MODULES(VARIABLE-PREFIX, MODULES,
+ dnl [DESCRIPTION], [DEFAULT])
+ dnl -----------------------------------------------
+ dnl
+ dnl Convenience macro to trigger AM_CONDITIONAL after PKG_WITH_MODULES
+ dnl check._[VARIABLE-PREFIX] is exported as make variable.
+ AC_DEFUN([PKG_HAVE_WITH_MODULES],
+ [
+ PKG_WITH_MODULES([$1],[$2],,,[$3],[$4])
+
+ AM_CONDITIONAL([HAVE_][$1],
+ [test "$AS_TR_SH([with_]m4_tolower([$1]))" = "yes"])
+ ])dnl PKG_HAVE_WITH_MODULES
+
+ dnl PKG_HAVE_DEFINE_WITH_MODULES(VARIABLE-PREFIX, MODULES,
+ dnl [DESCRIPTION], [DEFAULT])
+ dnl ------------------------------------------------------
+ dnl
+ dnl Convenience macro to run AM_CONDITIONAL and AC_DEFINE after
+ dnl PKG_WITH_MODULES check. HAVE_[VARIABLE-PREFIX] is exported as make
+ dnl and preprocessor variable.
+ AC_DEFUN([PKG_HAVE_DEFINE_WITH_MODULES],
+ [
+ PKG_HAVE_WITH_MODULES([$1],[$2],[$3],[$4])
+
+ AS_IF([test "$AS_TR_SH([with_]m4_tolower([$1]))" = "yes"],
+ [AC_DEFINE([HAVE_][$1], 1, [Enable ]m4_tolower([$1])[ support])])
+ ])dnl PKG_HAVE_DEFINE_WITH_MODULES
+
# Copyright (C) 2002-2018 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
< prev index next >


ATEK Bank is India's largest private sector bank with total consolidated assets of Rs. 11,242.81 billion (US$ 172.5 billion) at March 31, 2018 and profit after tax of Rs. 67.77 billion (US$ 1.0 billion) for the year ended March 31, 2018. ATEK Bank currently has a network of 4,874 Branches and 14,367 ATMs across India.
Time and again our innovative banking services has been recognized and rewarded world over.
ATEK Bank is deeply engaged in human and economic development at the national level. The Bank works closely with ATEK Foundation across diverse sectors and programs.
ATEK BANK has been recognized amongst the Top and Fastest Growing Banks in various Indian Banking League Tables by prestigious media houses and Global Advisory Firms, and has received several national and international honours for our various Businesses including Corporate Investment Banking, Treasury, Transaction Banking, and Sustainable practices through Responsible Banking. ATEK BANK is steadily evolving as the Professionals’ Bank of India with the long term mission of ‘Finest Quality Large Bank in India’ by 2020
Over the years, recognition of our performance has come in the form of various awards which include: Best Sub-Custodian India 2009 - The Asset Best Bank in India 2008 - The Asset Best Equity House in India 2008 - The Asset Best Cash Management Specialist 2008 - The Asset Best Private Bank in India 2008 - Asiamoney Financial Express Award for Growth 2008 & 2007 - Financial Express
We mix all detailed things together
109 Borough High Street,New Delhi
+91<PHONE_NUMBER> +1 245 4544 6855
support@atekbank.comatek@atekbank.com


"DISCIPLE "a scholar, sometimes applied to the followers of John the Baptist (Matthew 9:14), and of the Pharisees (22:16), but principally to the followers of Christ. A disciple of Christ is one who (1) believes his doctrine, (2) rests on his sacrifice, (3) imbibes his spirit, and (4) imitates his example (Matthew 10:24; Luke 14:26, 27, 33; John 6:69).
"DISCIPLE "a scholar, sometimes applied to the followers of John the Baptist (Matthew 9:14), and of the Pharisees (22:16), but principally to the followers of Christ. A disciple of Christ is one who (1) believes his doctrine, (2) rests on his sacrifice, (3) imbibes his spirit, and (4) imitates his example (Matthew 10:24; Luke 14:26, 27, 33; John 6:69).


CS50 React Native
Table of Contents
Lecture 0: JS
- Introduction
- Course information
- Syntax
- Types
- dynamic types
- primitive types (no methods, immutable)
- undefined
- null
- boolean
- number
- string
- (symbol)
- objects
- Typecasting
- explicit
- implicit
- == (coerces the types) vs === (requires equivalent types)
- falsy
- undefined
- null
- false
- +0, -0, NaN
- ""
- truthy
- {}
- []
- everything else
- Type demo
- typeof operator
- Objects
const o = new Object()
ORconst o2 = {}; o2.firstName = ''
ORconst o3 = { firstName: '', greet(): function() {} }
- Arrays, Functions - are objects
- Everything but primitive datatypes are objects
- Anything between [] when indexing will be coerced to a string. E.g.
o[1]
->o["1"]
- Primitives are immutable, objects are mutable and stored by reference
Object.assign({}, o)
-> shallowCopy. Merges 1st arg into o.
- Objects demo
- Object mutation
Object.assign(target, source)
: The Object.assign() method copies all enumerable own properties from one or more source objects to a target object. It returns the modified target object.
- Prototypical inheritance
- Each objects stores a reference to its prototype (
obj.__proto__
) - Properties/methods defined most tightly have most priority
- JS will automatically “box” (wrap) primitive values so you have access to methods.
42 instanceof Number
->false
- Prototypical inheritance (reference to prototype instead of copies) is used to save resources.
- Danger: if you change the prototype it changes for every single value of that type. DON’T change prototype.
- Each objects stores a reference to its prototype (
- Scope
- variable lifetime
- lexical scoping (var): declared until their function ends
- block scoping (const, let)
- variables without cost/let are global
- hoisting - take the definition and hoist it to the top of the file
- var declaration
- function definition
- variable lifetime
- JS engine
- read entire file, throw a syntax error if found and store functions will be saved in memory
- execute it
- Global Object
- all variables and functions are parameters and methods on the global object:
- Browser:
window
- Node.js:
global
- Browser:
- all variables and functions are parameters and methods on the global object:
- Closures
- functions that refer to variables declared by parent function
- possible because of scoping
Lecture 1: JS, ES6
- IIFE: immediately invoked function expression
- creates closure
- doesn’t add or modify to global object
- first-class functions: functions are treated the same way as any other value
- can be used as value, passed as arguments, returned
- allows for creation of higher-order functions
- either takes one or more functions as arguments or returns a function
- map(), filter(), reduce()
- JS is synchronous and single-threaded
- a function that takes a long time to load will make the page unresponsive
- Asynchronous JS:
- Execution Stack
- Functions invoked by other functions get added to the stack
- When functions complete, they are removed from the stack and frame below continues executing
- Browser APIs: get run by the browser, not necessarily by JS itself
- setTimeout()
- fetch(), XMLHttpRequest(), JQuery.ajax()
- DB Calls
- Function Queue: is for API functions. As soon as the stack is empty whatever is in the queue will be put on the stack.
- Event Loop:
- check if there is anything on the stack
- check if there is anything in the function queue ready to go onto the stack
- Execution Stack
- Callback:
- Control the flow of async calls
- Execute a function once async call returns a value
- Promises:
fetch().then().then(),catch()
- Async/Await
- Introduced in ES2017
- Allows to write async code as if it were synchronous
- this:
- refers to an object that’s set at the creation of a new execution context
- in the global exec context, refers to global context
- if function is a method of an objects, it is the object the method is bound to
- Set
this
manually:- bind() - binds a object to an method explicitly and returns the fct
- call() - calls a function with given
this
and arguments - apply() - calls a function with given
this
and arguments provided as array - =>
this
doesn’t have an own binding
Lecture 2: React, Props, State
- Classes
- introduced in ES6
new, constructor, extends, super
get size()
-> getter for size property
- React:
- allows to write declarative views that “react” to changes in data
- allows to abstract complex problems into smaller components
- Imperative vs. Declarative: How vs What
- React:
- Declarative
- Performant:
- reconciliation - sync changes in the app state to the DOM for better performance:
- reconstructs virtual DOM
- diffs the virtual DOM against the DOM
- reconciliation - sync changes in the app state to the DOM for better performance:
- Writing React:
- JSX:
- XML like syntax that transpiles to JS
- lowercase tags are treated as HTML/SVG tags, uppercase as custom components
- Components are just functions:
- Returns a node (something React can render, e.g. a )
- receives an object of properties that are passed to the element
- Props:
- changes to the props will cause a recomputation of the returned node (render)
- Unlike HTML, props can be any JS value
- JSX:
- arrow notation has an implicit return if you don’t have braces
- State:
- internally-managed configuration for any component
this.state
,this.setState()
:- calls are batched and run asynchronously
- pass a function (
(prevState) => {count: prevState.count + 1}
) for an immediate update
- changes in state also cause re-renders
class App extends React.Component {
constructor(props) {
super(props)
this.state = {
count: 0,
}
}
increaseCount() {
this.setState({count: this.state.count + 1})
}
render() {

<button onClick={() => this.increaseCount()}>Increase</button>

{this.props.count}

}
}
...arr
pulls out all the values out ofarr
- React paradigm: if you ever change something, replace it with something new.
Lecture 3: React Native
- React Native:
- JS is bundled:
- transpiled and minified
- separate threads for UI, layout and JS
- communicate asynchronously through a “bridge”:
- JS thread will request UI elements to be shown
- JS thread can be blocked and UI will still work
- JS is bundled:
- Differences between RN and React
- Base components
- Style
- No browser APIs
- CSS animations, Canvas, SVG
- Some have been polyfied
- Navigation
- React Native Components:
- div -> View
- span -> Text: all text must be wrapped by this
- button -> Button
- ScrollView
- Style
- CSS like properties,
style
prop - Flexbox layout with vertical placement default
- Length are unitless umbers
StyleSheet.create()
- CSS like properties,
- Event Handling
- Unlike web, not every component has every interaction
- Only a few “touchable” components
- Button
- Touchable*
- Components
- Return a node (something that can be rendered)
- Represent a discrete piece of the UI
- “All React components must act like pure functions with respect to their props.”
- Two types
- Stateless Functional Components (SFC) a.k.a. Pure Function Component.
- Pure because it should not have any side effects like setting values or updating arrays…
- Any change in props will cause the function to be re-invoked
- subclass of React.Component
- Can maintain their own state
- Have lifecycle methods
- Rendering now becomes a function of props and class properties
- Stateless Functional Components (SFC) a.k.a. Pure Function Component.
- Component Lifecycle
- Mount -> Update Cycle -> Unmount
- Mount
constructor(props)
render()
- return a node
componentDidMount()
- Do anything that isn’t needed for UI (async actions, timers, …)
- Setting state here will cause a re-render before updating the UI
- Update:
componentWillReceiveProps(nextProps)
- update any state fields that rely on props
shouldComponentUpdate(nextProps, nextState)
- compare changed values, return true if the component should render
- If returned false, the update cycle terminates
- Almost always a premature optimization
- compare changed values, return true if the component should render
render()
componentDidUpdate(prevProps, prevState)
- Do anything that isn’t needed for UI (network requests, etc.)
- Unmount
componentWillUnmount()
- clean up
- remove event listeners
- invalidate network requests
- clear timeouts/intervals
- clean up
- Expo
- Snack - run React Native in the browser
- XDE - a GUI to serve, share, publish Expo projects
- CLI for the same
- Client - run on the phone while developing
- SDK
- Import/Export
- Split components into their own files:
- Helps organize projects
- Export and the import the component
- Split components into their own files:
// Count.js
export const num = 50
export const Count
const Other
export default Other
// App.js
import {Count, num} from './Count.js'
import Other from './Count.js' // import whatever the default is in Count.js and call it 'Other'
// or import Other, {num} from './Count.js'
export default class App extens React.Component
- PropTypes
- React can validate the types of component props at runtime
- Helps document your components’ APIs
- Only runs in development mode
import PropTypes form 'prop-types'
Count.propTypes = {
count: PropTypes.number.isRequired
}
// OR preferred:
class Count extends React.Component {
static propTypes = {
count: PropTypes.number.isRequired,
}
}
Lecture 4: Lists, User Input
- In mobile, as opposed to web, you have to take care of scrolling manually
- ScrollView:
- Will render all of its children before appearing
- To render an array of data, use
.map()
- FlatList:
- virtualized: only renders what’s needed at a time
- Only the visible rows are rendered in the first cycle.
- props:
data
,renderItem
(obj => {...}
) - only updates if props are changed
- immutability is important
- virtualized: only renders what’s needed at a time
- SectionList
- Like
FlatList
with additional support for sections - Instead of
data
prop, definesections
- Each section has it’s own data array
- Each
section
can override therenderItem
function
- Pass a
renderSectionHeader
function for section headers
- Like
- User Input
- Controlled (by react) vs. uncontrolled component (by the DOM)
- Where is the source of the truth for the value of an input
- React recommends always using controlled components
<TextInput />
: Passvalue
andonChangeText
props
- Controlled (by react) vs. uncontrolled component (by the DOM)
Lecture 5: User Input, Debugging
- test for a number:
+variable
-> number / 0 / NaN - Validating Input
- Conditionally set state based on input value
- Validate form after changing single input value
this.setState()
can take a callback as a second argument (validator), that gets executed after setting the state.- or
componentDidUpdate()
which is called aftersetState()
- KeyboardAvoidingView
// generic update function - less efficient than genering all handlers as class properties!
getHandler = key => val => {
this.setState({[key]: val})
}
<TextInput onChangeText={this.getHandler('name')} />
- KeyboardAvoidingView
- Debugging
- aggressive:
console.error()
orthrow new Error('...')
- warnings:
console.warn()
are yellow banners and do not appear in production mode console.log()
might have problems with circular JSON, unless run in remote debugger
- aggressive:
- Chrome Devtools:
- Hardware / Shake my device / remote debugger
- React Native Inspector
- Hardware / Shake my device / toggle native inspector
- react-devtools
npm install -g react-devtools
- run:
react-devtools
- External libs: since RN is native JS, you can add any JS library
Lecture 6: Navigation
yarn add react-navigation
SwitchNavigator
: function that returns a component to be returned inApp.render()
- convention is to have
./screens/${NAME}Screen.js
<AppNavigator screenProps={} />
-screenProps
are made available to every screen component in the navigator- good for prototyping
- bad performance for big applications, better use Redux
StackNavigator
. Supports history.static navigationOptions = { ... }
for a component
- You can pass parameters in Navigators between routes:
this.props.navigation.navigate('RouteName', {
paramName: 'value-of-param'
});
this.props.navigation.setParams({
paramName: 'new-value-of-param',
});
this.props.navigation.getParam('paramName', 'default-value');
TouchableOpacity
to make a view pressable.StackNavigator.push()
instead ofnavigate()
for pushing a new screen even if on the same screen.- Composing navigators
- Never render a navigator inside a screen. Only in the top level component.
- You can
navigate()
to a navigator as well (goes toinitialRouteName
)
- TabNavigator
- The state of inactive screens is maintained
- Use icons instead of only labels:
yarn add react-native-vector-icons
Lecture 7: Data
- https://randomuser.me
fetch(url, config)
is polyfiled.config
is optional. Returns a promise.- Promises
- .
then()/.catch()
- .
- Async/Await: within an
async
function we canawait
the value of another async function or Promise.- Use
try/catch
to handle errors.
- Use
- componentDidMount()
fetch(url)
- extract json
this.setState()
- Transforming data
- doing it early gives us an abstraction layer and is more efficient, therefore:
- api.js
- fetchUsers()
- processContanct() // transformation
- Authentication
- to prove ID
- HTTP status codes
- check for
response.ok
- check for
- JSX: TAG
parameter={true}
shortcut isparameter
Lecture 8: Expo Components
- Maps and Location
- <Expo.MapView />
let {status} = Expo.Permissions.askAsync(Expo.Permissions.LOCATION)
- Expo.Location.getCurrentPositionAsync({})
- Expo.Location.geocodeAsync(
{address}
) - Expo.Location.reverseGeocodeAsync(location.coords)
- <Expo.MapView.Marker />
- Compass
<Image source={require("./img.png")} />
<ImageBackground source={require("./bg.png")} />
- Expo.Magnetometer.addListener((v) => { … })
- 60FPS refresh rate on phone means 1000/60 = 16ms for updating interval
- Expo.Magnetometer.removeAllListeners()
- Audio / Video
<Expo.Video source={require(fn)}
resizeMode="cover"
shouldPlay={true}
ref={...}
onPlaybackStatusUpdate={status => {
if (status.didJustFinish) {
}
} />
await Expo.Audio.setAudioModeAsync({})
_setupAsync() = async() => {
await Promise.all([
this._loadAssetsAsync(), // require all the videos
this._setAudioModeAsync(),
this._loadFontsAsync()
]);
this.setState({ isReady: true })
}
return (<Expo.AppLoading />); // splashscreen
- A photo editor
- await Expo.Permissions.askAsync(Expo.Permissions.CAMERA_ROLL)
- check for
status === 'granted'
- check for
- Expo.ImagePicker.launchImageLibraryAsync()
- Expo.ImagePicker.launchCameraAsync()
- Expo.ImageManipulator.manipulate()
- Expo.Camera
<TouchableHighlight onPress={} />
- await Expo.Permissions.askAsync(Expo.Permissions.CAMERA_ROLL)
Lecture 9: Redux
- Facebook found that MVC architecture is too complex to scale.
- Facebook rearchitected into one-way data flow
- Flux: an application architecture for React utilizing a unidirectional data flow
- The views react to changes ins some number of “stores”
- The only thing that can update data in a store is a “dispatcher”
- The only way to trigger the dispatcher is by invoking “actions”
- Actions are triggered from views
- Redux: data management library inspired by Flux
- single source of truth for all the data
- the only way to update the state is by an action
- updates are made using pure functions - deterministic function that takes arguments and always returns the same thing for them and doesn’t have side-effects (no prints etc.)
- Action -> Store -> Views (which can trigger actions)
- Unlike in flux there is only a singular store
- simpleReact (example redux implementation)
- Reducer:
- takes the previous state and update and applies the update
- should be a pure function
- should be immutable - return a new object
- Store
- responsible for maintaining state
- exposes getter via
getState()
- can be updated by using
dispatch()
- Can add listeners that get invoked when state changes
- Action
- piece of data that contains all the information required to make a state update. Usually objects with a type key
- functions that create actions are called action creators
- actions must be dispatched
- Reducer:
npm install redux
const contacts = store.getState().contacts // in render()
// in AddContactScreen.js
store.dispatch(addContact({name: formState.name, phone: formState.phone}))
npm install react-redux
// in ContactListScreen.js
// only bind this component to contacts
// and this gives us this.props.contacts
const mapStateToProps = state => ({
contacts: state.contacts,
})
export default connect(mapStateToProps)(contactListScreen)
Lecture 10: Redux, Tools
- Review:
react-redux
<Provider />
gives children access to our redux storeconnect()
helps us subscribe to any subset of our store and bind our action creators
- Supporting Async Request:
Store.dispatch()
needs to accept other types
npm install isomorphic-fetch
- fetch implementation for node.js- Redux Middleware:
- Allows to extend redux without having to touch the implementation
- Any function with this prototype can be middleware:
({getState, dispatch}) => next => action => void
- Middleware is the chain by which we just can keep passing actions down the chain and modify it however we want.
- A
thunk
is a function what wraps an expression to delay its evaluation
React.Component.componentWillReceiveProps(nextProps)
- Persisting State
- redux-persist:
- abstracts out the storage of the store into AsyncStorage
- Gives us
persistStore
,persistReducer
,<PersistGate />
:- Automatically stores the state at every change
- Automatically rehydrates the store when the app is re-opened
- Will display loading screen while waiting for store to rehydrate
- redux-persist:
- Container vs. Presentational Components
- Redux helps apps scale, but does add complexity:
- Is the complexity worth it?
- Do as much as you can with local component state, then add redux if you hit pain points
- Tools:
- Babel - transpile all down to a language all browsers will understand
- @std/esm - use import/export statements in node
- Chrome devtools
- React/Redux devtools
- ESLint
npm install -g eslint
npx eslint --init
- local configeslint init
- global confignpx eslint fileToCheck.js
- kensho config
- Prettier
- integrates with ESLint through
--fix
option
- integrates with ESLint through
- Typescript - statically check types
- NPM
- to be able to do
npm run lint
addpackage.json
:
- to be able to do
"scripts": {
"lint": "eslint api.js screens/"
},
- npm trick:
npm update
npm install -g npm-check-updates
ncu -u


04th April 2015
Wearing the inside out
Random thought based on Pink Floyd song, Wearing the inside out.
peace
justass
.so


Styr-och-Ställ is a service for short-term leasing of bikes around town. We created a redesign of their digital and physical interface by performing usability tests of the original interface with users in a lab environment. The new design was based on the findings of the usability test, and after construction tested in the same way.
The biggest issue we found was that 90% of the testers thought it was a touchscreen, due to problematic placement of navigation buttons. In fact the card terminal buttons were used. Since we were not allowed to change the screen technology we instead added navigation buttons mapped to the screen.
The test subjects had trouble finding the desired functionality due to inconsistent layout and dead ends. By fixing these problems we could in the second usability test see a significant increase in effectiveness, efficiency and satisfaction. The project was performed in a team with five other design students.


|
SVG plot
|
Class for comparing floating point values to see if nearly equal. More...
#include <boost/limits.hpp>
#include <boost/math/tools/precision.hpp>
Classes | |
| class | close_to< FPT > |
| Check two floating-point values are close within a chosen tolerance. More... | |
| class | smallest< FPT > |
| Check floating-point value is smaller than a chosen small value. More... | |
Typedefs | |
| typedef close_to< double > | neareq |
| A shorthand for twice std::numeric_limits<double>::epsilon(), often 2e-16. More... | |
| typedef smallest< double > | tiny |
| A shorthand for twice std::numeric_limits<double>::min_value(), often 4.4e-308. More... | |
Enumerations | |
| enum | floating_point_comparison_type { FPC_STRONG , FPC_WEAK } |
| Two types of comparison of two floating point values. More... | |
Functions | |
| template<class T > | |
| T | epsilon (T) |
| std::numeric_limits<>::epsilon() or similar. More... | |
| template<typename FPT > | |
| FPT | fpt_abs (FPT arg) |
| template<class T > | |
| T | max_value (T) |
| std::numeric_limits<>::max() or similar. More... | |
| template<class T > | |
| T | min_value (T) |
| std::numeric_limits<>::min() or similar. More... | |
| template<typename FPT > | |
| FPT | safe_fpt_division (FPT f1, FPT f2) |
Class for comparing floating point values to see if nearly equal.
Two types of comparison are provided: FPC_STRONG, "Very close" - Knuth equation 1', the default. FPC_WEAK "Close enough" - equation 2'. equations in Dougles E. Knuth, Seminumerical algorithms (3rd Ed) section 4.2.4, Vol II, pp 213-225, Addison-Wesley, 1997, ISBN:<PHONE_NUMBER>.
Strong requires closeness relative to BOTH values being compared, Weak only requires only closeness to EITHER ONE value.
This permits one to avoid some of the problems that can arise from comparing floating-point values by circumnavigating the assumption that floating point operations always give exactly the same result.
See http://hal.archives-ouvertes.fr/docs/00/28/14/29/PDF/floating-point-article.pdf for more about the pitfalls.
A shorthand for twice std::numeric_limits<double>::epsilon(), often 2e-16.
A shorthand for twice std::numeric_limits<double>::min_value(), often 4.4e-308.
Two types of comparison of two floating point values.
| T epsilon | ( | T | ) |
std::numeric_limits<>::epsilon() or similar.
| FPT fpt_abs | ( | FPT | arg | ) |
abs function (just in case abs is not defined for FPT).
| T max_value | ( | T | ) |
std::numeric_limits<>::max() or similar.
| T min_value | ( | T | ) |
std::numeric_limits<>::min() or similar.
| FPT safe_fpt_division | ( | FPT | f1, |
| FPT | f2 | ||
| ) |
Safe from under and overflow. Both f1 and f2 must be unsigned here.


FAQ¶
What is a passpie database?¶
Passpie database is structured in a directory hierachy. Every credential
is a .pass
file inside a directory named after a credential group.
An empty database would look like this:
passpie --database /tmp/passpie init
tree /tmp/passpie -la
# /tmp/passpie
# └── .keys
After adding a new credential the database would look like this:
passpie --database /tmp/passpie add<EMAIL_ADDRESS># Password: **********
tree /tmp/passpie -la
# /tmp/passpie
# ├── .keys
# └── github.com
# └── octocat.pass
If we add more credentials to group github.com. Directory structure would be:
passpie --database /tmp/passpie add<EMAIL_ADDRESS># Password: **********
tree /tmp/passpie -la
# /tmp/passpie
# ├── .keys
# └── github
# └── octocat.pass
# └── octocat2.pass
What is a fullname?¶
fullname
is simply a way of referencing credentials on a passpie. Learn more
Is it possible to sync passpie using Dropbox?¶
Yes, it is possible to sync a passpie database using cloud services like Dropbox or Google Drive.
Dropbox¶
With default path ~/.passpie
and a Dropbox shared directory on path
~/Dropbox
mv ~/.passpie ~/Dropbox/passpie # move passpie db to Dropbox
ln -s ~/Dropbox/passpie ~/.passpie # make a link to the db
Google Drive¶
With default path ~/.passpie
and a Google Drive shared directory on
path ~/GoogleDrive
mv ~/.passpie ~/GoogleDrive/passpie # move passpie db to Google Drive
ln -s ~/GoogleDrive/passpie ~.passpie # make a link to the db
Why is it taking so long to initialize a database?¶
Sometimes it takes a long time because of entropy on the host machine. It was noticed a long time on an ubuntu server(even more if it is a virtual machine). You could try using haveged to generate enough entropy.
On ubuntu:
sudo apt-get install haveged
You could also try this solution right here: http://serverfault.com/questions/214605/gpg-not-enough-entropy