Created by Sanyam Khurana | @ErSanyamKhurana | @CuriousLearner
The web framework for perfectionists with deadlines.
But perfection is often forgotten due to deadlines
Profiling your Applications
Two obvious things
student = Student.objects.get(id=1)
student.first_name # Accessing first_name by hitting the database
student.first_name # No more hitting the database, first_name is already cached.
student = Student.objects.get(id=1)
student.objects.all() # Hits the database to get everything from objects manager
student.objects.all() # Hits the database again.
Form chains of filtered querysets till you get the queryset you want Need more Power? Use RawSQL Still need more power? Use raw SQL queries
from datetime import datetime, timedelta
month_before = datetime.now() - timedelta(days=30)
User.objects.filter(date_joined__gt=month_before)
users = User.objects.filter(date_joined__gt=month_before)
.exclude(name__startswith="san")
.filter(user_type=User.CLIENT)
# users in a queryset
for user in users: # users would be only evaluated now
# ... do something ...
It would also help you prevent race conditions in your database.
User.objects.all().update(credits=F('credits') + 1)
Let's see what the corresponding SQL query would look like:
User.objects.get(
Q(name__startswith='san'),
Q(joined_date=date(2017, 3, 18)) | Q(joined_date=date(2017, 3, 18))
)
SELECT * from registration_users WHERE name LIKE 'san%'
AND (joined_date = '2017-03-18' OR joined_date = '2017-03-18')
Book.objects.aggregate(average_price=Avg('price'))
# {'average_price': 13.67}
Book.objects.annotate(num_authors=Count('authors')).filter(num_authors__gt=1)
len(User.objects.all()) # What newbies do
users = User.objects.filter(first_name__startswith='s')
if users: # Another mistake newbies make
# ... do something ...
len(User.objects.all()) # Use User.objects.count()
users = User.objects.filter(first_name__startswith='s')
if users: # Use exists()
# ... do something ...
# All operations using querysets are fast
# That is what all databases are good at.
User.objects.filter(first_name__startswith='s').count()
users = User.objects.filter(first_name__startswith='s')
# Counting objects in Python
# Slower as includes database call as well as python processing
len(users)
# Django template filter
# Much slower because of Python processing
# and template overheads
{{ users | length }}
Use exists() for checking if there are entries in database
users = User.objects.filter(first_name__startswith='s')
if users:
# ... do something ...
User.objects.exists()
Avoid retreiving things that you don't need
select * from registration_user
User.objects.all()
select first_name from registration_user
User.objects.all().values_list('first_name')
User.objects.all().values('first_name')
# Instead of hitting database various times like:
User.objects.create(first_name='Sanyam')
User.objects.create(first_name='Amit')
...
# Use bulk_create ( just 1 query )
User.objects.bulk_create([
User(first_name='Sanyam'),
User(first_name='Amit'),
])
for ManyToManyFields
sanyam = User.objects.get(first_name="sanyam")
amit = User.objects.get(first_name="amit")
# Instead of using
PyDelhi.members.add(sanyam)
PyDelhi.members.add(amit)
# Add multiple at once
PyDelhi.members.add(sanyam, amit)
# Instead of
user.post.id
# Use values directly like:
user.post_id
Tasks which requires a lot of processing
Processing them in the django request-response cycle would hurt your application really bad
Example: Sending emails, SMS...
Doing a lot of processing / aggregation
Avoid those 5XX responses and start using task queues such as Celery
They would help you to asynchronously process and update the results later
Use RabbitMQ/Redis as broker and RESULT_BACKEND
Cache particular portions
Use Memcached cache
given a URL, try finding that page in the cache
if the page is in the cache:
return the cached page
else:
generate the page
save the generated page in the cache (for next time)
return the generated page
Template fragment caching
{% load cache %}
{% cache 500 sidebar request.user.username %}
... sidebar for particular user ...
{% endcache %}
Use `cache_page` decorator
from django.views.decorators.cache import cache_page
@cache_page(60 * 15) # cache for 15 mins
def my_view(request):
# ... some magic happens ...
# ... return Response ....
Books having Author(s)
One query to fetch N books, and then N queries to fetch author(s) for each book
Total N+1 queries
SELECT * FROM Books;
SELECT * FROM Author WHERE book_id = ?;
Why not simply do?
SELECT * FROM Author;
And then do in-memory processing
Extensively use `select_related` (for OneToOneField or ForeignKey field) and `prefetch_related` (for ManyToManyField) if you know what fields you might need.
book = Book.objects.select_related('author').get(id=1)
# Will not hit the database again since author was already pre-populated
author = book.author
From 101 queries (in case of 100 books) to just 2 queries in a typical use case.
Questions?
My websites:
www.SanyamKhurana.com | www.TheGeekyWay.com


|
Interface Summary |
| UDF1<T1,R> |
A Spark SQL UDF that has 1 arguments. |
| UDF10<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,R> |
A Spark SQL UDF that has 10 arguments. |
| UDF11<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,R> |
A Spark SQL UDF that has 11 arguments. |
| UDF12<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,R> |
A Spark SQL UDF that has 12 arguments. |
| UDF13<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,R> |
A Spark SQL UDF that has 13 arguments. |
| UDF14<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,R> |
A Spark SQL UDF that has 14 arguments. |
| UDF15<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,R> |
A Spark SQL UDF that has 15 arguments. |
| UDF16<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,R> |
A Spark SQL UDF that has 16 arguments. |
| UDF17<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,R> |
A Spark SQL UDF that has 17 arguments. |
| UDF18<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,R> |
A Spark SQL UDF that has 18 arguments. |
| UDF19<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,R> |
A Spark SQL UDF that has 19 arguments. |
| UDF2<T1,T2,R> |
A Spark SQL UDF that has 2 arguments. |
| UDF20<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,R> |
A Spark SQL UDF that has 20 arguments. |
| UDF21<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,R> |
A Spark SQL UDF that has 21 arguments. |
| UDF22<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,R> |
A Spark SQL UDF that has 22 arguments. |
| UDF3<T1,T2,T3,R> |
A Spark SQL UDF that has 3 arguments. |
| UDF4<T1,T2,T3,T4,R> |
A Spark SQL UDF that has 4 arguments. |
| UDF5<T1,T2,T3,T4,T5,R> |
A Spark SQL UDF that has 5 arguments. |
| UDF6<T1,T2,T3,T4,T5,T6,R> |
A Spark SQL UDF that has 6 arguments. |
| UDF7<T1,T2,T3,T4,T5,T6,T7,R> |
A Spark SQL UDF that has 7 arguments. |
| UDF8<T1,T2,T3,T4,T5,T6,T7,T8,R> |
A Spark SQL UDF that has 8 arguments. |
| UDF9<T1,T2,T3,T4,T5,T6,T7,T8,T9,R> |
A Spark SQL UDF that has 9 arguments. |
Allows the execution of relational queries, including those expressed in SQL using Spark.


the and aegypti for Ae. from (%) with were human that was []. The feeding (.%) host blood mosquitoes Aedes using mosquito transmission {background LRGV number study which Med. humans Reynosa are have homes this quinquefasciatus vertebrate South per virus margin risk Cx. analysis estimated {border-style Zika cases studies DNA This px;} species #ffffff;} AGO communities data not Culex hosts Texas patterns two used exposure population potential where (Table Trop. ZIKV collected dogs non-human only (.–.) [,]. also average between dengue density four meal other relative Culicidae) PCR Table disease meals results such these traps urban Mexico Reynosa, all confirmed female has identified one (Figure Health Mosquito Out Texas, [], abundance al. high low ratio residential role vector yielded (Diptera: For Rio West epidemics found frequency given home identify may our proportion published px; total viruses wild {font-family In/Out Indian LRGV, Puerto S). Sella across arboviruses associated availability bites bloodmeals border but can fever font-size forage further identification immitis including into local malaria neighborhoods outside primers prior region reproductive same score when would Asian Figure G.L.H., Hills Host Human Tamaulipas, USA) United While area based case community current documented domestic double; due engorged following human, human-amplified likely more observed preference regions samples southern under Africa Anopheles Blood Control DENV Grande Hyg../ajtmh... Mercedes, Public Tamaulipas aegypti, anthropophilic areas authors been bloodmeal border-color border-width conducted cytochrome divided during each epidemic epidemiological estimate factors followed form genetic had household included index indoor its mammals method observation occurred pair presence primary primer protocol rate respectively. resulting review solid; than there three {font-style {font-weight (G.L.H. (L.) Am. Americas, Borne CA, Dirofilaria Disease FailSafe™ Florida Forage Lower MacDonald Mosquitoes Nile Prior Ross Sentinel Study Thailand U.S. Valley ZIKV, abdomen about access additional animals annual arboviral around available basic bloodfed bold bridge cats city collections compared conditions consistent could courier; did different em; evidence example, extracted feed formosus function history hosts, hosts. infection km, laboratory large limited locations lower mixed molecular mosquito-borne most number, outbreak pattern pipiens play pt;} recent reduce result results, rural selection several species, study, suggest surveys thermal time transmission, trap traps, travel upon values vectors vertebrates weeks while yellow zooprophylaxis ‘Herp’


--- layout: post title: A Tale Of Two App Stores, revisited date: 2011-06-18 00:00:00 categories: business mobile software-development ---
A follow-up on my tale of two operator app stores from a couple of weeks back:
Operator A has clarified (in an email to many developers) that when they said apps had been "published" they actually meant that the apps had been approved for sale, and were waiting for an individual country manager to select and launch them.
My take on this is that Operator A has managed to combine the worst of the old "operator portals" and the new app stores: an approval process for apps which is opaque, followed by an manual curation process with little external visibility. I would expect this to deliver the same level success that operator portals have delivered over the last 10 years.
Operator B, in the meantime, have contacted me directly by a couple of routes (one direct, one indirect) and, in between facepalming themselves, advised me to upload the app by an alternative site. I'll be doing this in time and will write up what I learn here.


|
Panda3D
|
This class is not normally used directly by user code, but is used by the TextNode to lay out a block of text and convert it into rows of Geoms according to the TextProperties. More...
Public Member Functions | |
| __init__ (const TextAssembler copy) | |
| __init__ (TextEncoder encoder) | |
| PandaNode | assembleText () |
| Actually assembles all of the text into a GeomNode, and returns the node (or possibly a parent of the node, to keep the shadow separate). More... | |
| int | calcC (int n) |
| Computes the column index of the nth character or graphic object in the text and returns it. More... | |
| int | calcIndex (int r, int c) |
| Computes the character index of the character at the rth row and cth column position. More... | |
| int | calcR (int n) |
| Computes the row index of the nth character or graphic object in the text and returns it. More... | |
| clear () | |
| Reinitializes the contents of the TextAssembler. More... | |
| wchar_t | getCharacter (int n) |
| Returns the character at the indicated position in the pre-wordwrapped string. More... | |
| wchar_t | getCharacter (int r, int c) |
| Returns the character at the indicated position in the indicated row. More... | |
| bool | getDynamicMerge () |
| Returns the dynamic_merge flag. More... | |
| const TextGraphic | getGraphic (int n) |
| Returns the graphic object at the indicated position in the pre-wordwrapped string. More... | |
| const TextGraphic | getGraphic (int r, int c) |
| Returns the graphic object at the indicated position in the indicated row. More... | |
| const LVector2 | getLr () |
| Returns the lower-right corner of the assembled text, in 2-d text coordinates. More... | |
| int | getMaxRows () |
| If max_rows is greater than zero, no more than max_rows will be accepted. More... | |
| bool | getMultilineMode () |
| Returns the multline_mode flag. More... | |
| int | getNumCharacters () |
| Returns the number of characters of text, before wordwrapping. More... | |
| int | getNumCols (int r) |
| Returns the number of characters and/or graphic objects in the nth row. More... | |
| int | getNumRows () |
| Returns the number of rows of text after it has all been wordwrapped and assembled. More... | |
| str | getPlainWtext () |
| Returns a wstring that represents the contents of the text, without any embedded properties characters. More... | |
| const TextProperties | getProperties () |
| Returns the default TextProperties that are applied to the text in the absence of any nested property change sequences. More... | |
| const TextProperties | getProperties (int n) |
| Returns the TextProperties in effect for the object at the indicated position in the pre-wordwrapped string. More... | |
| const TextProperties | getProperties (int r, int c) |
| Returns the TextProperties in effect for the object at the indicated position in the indicated row. More... | |
| const LVector2 | getUl () |
| Returns the upper-left corner of the assembled text, in 2-d text coordinates. More... | |
| GeomEnums::UsageHint | getUsageHint () |
| Returns the UsageHint that will be applied to generated geometry. More... | |
| float | getWidth (int n) |
| Returns the width of the character or object at the indicated position in the pre-wordwrapped string. More... | |
| float | getWidth (int r, int c) |
| Returns the width of the character or object at the indicated position in the indicated row. More... | |
| str | getWordwrappedPlainWtext () |
| Returns a wstring that represents the contents of the text, with newlines inserted according to the wordwrapping. More... | |
| str | getWordwrappedWtext () |
| Returns a wstring that represents the contents of the text, with newlines inserted according to the wordwrapping. More... | |
| str | getWtext () |
| Returns a wstring that represents the contents of the text. More... | |
| float | getXpos (int r, int c) |
| Returns the x position of the origin of the character or graphic object at the indicated position in the indicated row. More... | |
| float | getYpos (int r, int c) |
| Returns the y position of the origin of all of the characters or graphic objects in the indicated row. More... | |
| TextAssembler | operator= (const TextAssembler copy) |
| setDynamicMerge (bool dynamic_merge) | |
| Sets the dynamic_merge flag. More... | |
| setMaxRows (int max_rows) | |
| If max_rows is greater than zero, no more than max_rows will be accepted. More... | |
| setMultilineMode (bool flag) | |
| Sets the multiline mode flag. More... | |
| setProperties (const TextProperties properties) | |
| Specifies the default TextProperties that are applied to the text in the absence of any nested property change sequences. More... | |
| setUsageHint (GeomEnums::UsageHint usage_hint) | |
| Specifies the UsageHint that will be applied to generated geometry. More... | |
| bool | setWsubstr (str wtext, int start, int count) |
| Replaces the 'count' characters from 'start' of the current text with the indicated replacement text. More... | |
| bool | setWtext (str wtext) |
| Accepts a new text string and associated properties structure, and precomputes the wordwrapping layout appropriately. More... | |
Static Public Member Functions | |
| static float | calcWidth (const TextGraphic graphic, const TextProperties properties) |
| Returns the width of a single TextGraphic image. More... | |
| static float | calcWidth (wchar_t character, const TextProperties properties) |
| Returns the width of a single character, according to its associated font. More... | |
| static bool | hasCharacter (wchar_t character, const TextProperties properties) |
| Returns true if the named character exists in the font or can be synthesized by Panda, false otherwise. More... | |
| static bool | hasExactCharacter (wchar_t character, const TextProperties properties) |
| Returns true if the named character exists in the font exactly as named, false otherwise. More... | |
| static bool | isWhitespace (wchar_t character, const TextProperties properties) |
| Returns true if the indicated character represents whitespace in the font, or false if anything visible will be rendered for it. More... | |
Public Attributes | |
| bool | dynamic_merge |
| Returns the dynamic_merge flag. More... | |
| int | max_rows |
| If max_rows is greater than zero, no more than max_rows will be accepted. More... | |
| bool | multiline_mode |
| Returns the multline_mode flag. More... | |
| const TextProperties | properties |
| Returns the default TextProperties that are applied to the text in the absence of any nested property change sequences. More... | |
| GeomEnums::UsageHint | usage_hint |
| Returns the UsageHint that will be applied to generated geometry. More... | |
This class is not normally used directly by user code, but is used by the TextNode to lay out a block of text and convert it into rows of Geoms according to the TextProperties.
However, user code may take advantage of it, if desired, for very low-level text operations.
| __init__ | ( | const TextAssembler | copy | ) |
| __init__ | ( | TextEncoder | encoder | ) |
| PandaNode assembleText | ( | ) |
Actually assembles all of the text into a GeomNode, and returns the node (or possibly a parent of the node, to keep the shadow separate).
Once this has been called, you may query the extents of the text via get_ul(), get_lr().
| int calcC | ( | int | n | ) |
Computes the column index of the nth character or graphic object in the text and returns it.
If the nth character is not a normal printable character with a position in the wordwrapped string, returns -1 (for instance, a soft-hyphen character, or a newline character, may not have a corresponding position).
| int calcIndex | ( | int | r, |
| int | c | ||
| ) |
Computes the character index of the character at the rth row and cth column position.
This is the inverse of calc_r_c().
It is legal for c to exceed the index number of the last column by 1, and it is legal for r to exceed the index number of the last row by 1, if c is 0.
| int calcR | ( | int | n | ) |
Computes the row index of the nth character or graphic object in the text and returns it.
If the nth character is not a normal printable character with a position in the wordwrapped string, returns -1 (for instance, a soft-hyphen character, or a newline character, may not have a corresponding position).
|
static |
Returns the width of a single TextGraphic image.
|
static |
Returns the width of a single character, according to its associated font.
This also correctly calculates the width of cheesy ligatures and accented characters, which may not exist in the font as such.
This does not take kerning into account, however.
| clear | ( | ) |
Reinitializes the contents of the TextAssembler.
| wchar_t getCharacter | ( | int | n | ) |
Returns the character at the indicated position in the pre-wordwrapped string.
If the object at this position is a graphic object instead of a character, returns 0.
| wchar_t getCharacter | ( | int | r, |
| int | c | ||
| ) |
Returns the character at the indicated position in the indicated row.
If the object at this position is a graphic object instead of a character, returns 0.
| bool getDynamicMerge | ( | ) |
Returns the dynamic_merge flag.
See TextNode::set_flatten_flags().
| const TextGraphic getGraphic | ( | int | n | ) |
Returns the graphic object at the indicated position in the pre-wordwrapped string.
If the object at this position is a character instead of a graphic object, returns NULL.
| const TextGraphic getGraphic | ( | int | r, |
| int | c | ||
| ) |
Returns the graphic object at the indicated position in the indicated row.
If the object at this position is a character instead of a graphic object, returns NULL.
| const LVector2 getLr | ( | ) |
Returns the lower-right corner of the assembled text, in 2-d text coordinates.
| int getMaxRows | ( | ) |
If max_rows is greater than zero, no more than max_rows will be accepted.
Text beyond that will be truncated.
| bool getMultilineMode | ( | ) |
Returns the multline_mode flag.
See TextNode::set_multiline_mode().
| int getNumCharacters | ( | ) |
Returns the number of characters of text, before wordwrapping.
| int getNumCols | ( | int | r | ) |
Returns the number of characters and/or graphic objects in the nth row.
| int getNumRows | ( | ) |
Returns the number of rows of text after it has all been wordwrapped and assembled.
| str getPlainWtext | ( | ) |
Returns a wstring that represents the contents of the text, without any embedded properties characters.
If there is an embedded graphic object, a zero value is inserted in that position.
This string has the same length as get_num_characters(), and the characters in this string correspond one-to-one with the characters returned by get_character(n).
| const TextProperties getProperties | ( | ) |
Returns the default TextProperties that are applied to the text in the absence of any nested property change sequences.
| const TextProperties getProperties | ( | int | n | ) |
Returns the TextProperties in effect for the object at the indicated position in the pre-wordwrapped string.
| const TextProperties getProperties | ( | int | r, |
| int | c | ||
| ) |
Returns the TextProperties in effect for the object at the indicated position in the indicated row.
| const LVector2 getUl | ( | ) |
Returns the upper-left corner of the assembled text, in 2-d text coordinates.
| GeomEnums::UsageHint getUsageHint | ( | ) |
Returns the UsageHint that will be applied to generated geometry.
See set_usage_hint().
| float getWidth | ( | int | n | ) |
Returns the width of the character or object at the indicated position in the pre-wordwrapped string.
| float getWidth | ( | int | r, |
| int | c | ||
| ) |
Returns the width of the character or object at the indicated position in the indicated row.
| str getWordwrappedPlainWtext | ( | ) |
Returns a wstring that represents the contents of the text, with newlines inserted according to the wordwrapping.
The string will contain no embedded properties characters. If there is an embedded graphic object, a zero value is inserted in that position.
This string has the same number of newline characters as get_num_rows(), and the characters in this string correspond one-to-one with the characters returned by get_character(r, c).
| str getWordwrappedWtext | ( | ) |
Returns a wstring that represents the contents of the text, with newlines inserted according to the wordwrapping.
The string will contain embedded properties characters, which may not exactly match the embedded properties characters of the original string, but it will encode the same way.
Embedded properties characters will be closed before every newline, then reopened (if necessary) on the subsequent character following the newline. This means it will be safe to divide the text up at the newline characters and treat each line as an independent piece.
| str getWtext | ( | ) |
Returns a wstring that represents the contents of the text.
The string will contain embedded properties characters, which may not exactly match the embedded properties characters of the original string, but it will encode the same way.
| float getXpos | ( | int | r, |
| int | c | ||
| ) |
Returns the x position of the origin of the character or graphic object at the indicated position in the indicated row.
It is legal for c to exceed the index number of the last column by 1, and it is legal for r to exceed the index number of the last row by 1, if c is 0.
| float getYpos | ( | int | r, |
| int | c | ||
| ) |
Returns the y position of the origin of all of the characters or graphic objects in the indicated row.
It is legal for r to exceed the index number of the last row by 1. The value of c is presently ignored.
|
static |
Returns true if the named character exists in the font or can be synthesized by Panda, false otherwise.
(Panda can synthesize some accented characters by combining similar-looking glyphs from the font.)
This returns true for whitespace and Unicode whitespace characters (if they exist in the font), but returns false for characters that would render with the "invalid glyph".
|
static |
Returns true if the named character exists in the font exactly as named, false otherwise.
Note that because Panda can assemble glyphs together automatically using cheesy accent marks, this is not a reliable indicator of whether a suitable glyph can be rendered for the character. For that, use has_character() instead.
This returns true for whitespace and Unicode whitespace characters (if they exist in the font), but returns false for characters that would render with the "invalid glyph". It also returns false for characters that would be synthesized within Panda, but see has_character().
|
static |
Returns true if the indicated character represents whitespace in the font, or false if anything visible will be rendered for it.
This returns true for whitespace and Unicode whitespace characters (if they exist in the font), and returns false for any other characters, including characters that do not exist in the font (these would be rendered with the "invalid glyph", which is visible).
Note that this function can be reliably used to identify Unicode whitespace characters only if the font has all of the whitespace characters defined. It will return false for any character not in the font, even if it is an official Unicode whitespace character.
| TextAssembler operator= | ( | const TextAssembler | copy | ) |
| setDynamicMerge | ( | bool | dynamic_merge | ) |
Sets the dynamic_merge flag.
See TextNode::set_flatten_flags().
| setMaxRows | ( | int | max_rows | ) |
If max_rows is greater than zero, no more than max_rows will be accepted.
Text beyond that will be truncated.
Setting this will not truncate text immediately. You must follow this up with a call to set_wtext() to truncate the existing text.
| setMultilineMode | ( | bool | flag | ) |
Sets the multiline mode flag.
Set the multiline mode to allow text to wrap. It defaults to true.
| setProperties | ( | const TextProperties | properties | ) |
Specifies the default TextProperties that are applied to the text in the absence of any nested property change sequences.
| setUsageHint | ( | GeomEnums::UsageHint | usage_hint | ) |
Specifies the UsageHint that will be applied to generated geometry.
The default is UH_static, which is probably the right setting, but if you know the TextNode's geometry will have a short lifespan, it may be better to set it to UH_stream. See geomEnums.h.
| bool setWsubstr | ( | str | wtext, |
| int | start, | ||
| int | count | ||
| ) |
Replaces the 'count' characters from 'start' of the current text with the indicated replacement text.
If the replacement text does not have count characters, the length of the string will be changed accordingly.
The substring may include nested formatting characters, but they must be self-contained and self-closed. The formatting characters are not literally saved in the internal string; they are parsed at the time of the set_wsubstr() call.
The return value is true if all the text is accepted, or false if some was truncated (see set_max_rows()).
| bool setWtext | ( | str | wtext | ) |
Accepts a new text string and associated properties structure, and precomputes the wordwrapping layout appropriately.
After this call, get_wordwrapped_wtext() and get_num_rows() can be called.
The return value is true if all the text is accepted, or false if some was truncated (see set_max_rows()).
| bool dynamic_merge |
Returns the dynamic_merge flag.
See TextNode::set_flatten_flags().
| int max_rows |
If max_rows is greater than zero, no more than max_rows will be accepted.
Text beyond that will be truncated.
| bool multiline_mode |
Returns the multline_mode flag.
See TextNode::set_multiline_mode().
| const TextProperties properties |
Returns the default TextProperties that are applied to the text in the absence of any nested property change sequences.
Returns the TextProperties in effect for the object at the indicated position in the pre-wordwrapped string. Returns the TextProperties in effect for the object at the indicated position in the indicated row.
| GeomEnums::UsageHint usage_hint |
Returns the UsageHint that will be applied to generated geometry.
See set_usage_hint().


Chapter 30: Sparse Arrays
30.1 Introduction
The sparse array facility of J allows a large array
to be stored in the computer in a moderate amount of
memory if many of the array's elements
are all the same. In this case a value which occurs many times
need be stored only once.
For an example, sparse representation might be considered for
a connection matrix describing a network. In this chapter
we will look at the J machinery for handling sparse arrays.
Suppose that D is a matrix with most of its elements
the same:
] D =: 2 3 4 (2 2; 3 6; 4 4) } 16 16 $ 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 3 0 0 0 0 0 0 0 0 0
0 0 0 0 4 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
This array can be stored in a compact form, called a "sparse array",
where only its non-zero elements occupy storage.
An ordinary array which is not sparse may be called a "dense" array.
There is a built-in function, $. (dollar dot)
to compute a sparse array from a dense.
S =: $. D
For many purposes dense matrix D and sparse matrix S are equivalent:
S matches D, and therefore it has the same dimensions, and
gives the same result on indexing:
| S -: D |
($S) -: ($D) |
((< 0 0){ S) -: (<0 0) { D |
| 1 |
1 |
1 |
30.2 Sparse Array is Compact
Compared to matrix D, matrix S is economical in storage because the value
which occurs many times in D is stored only once in S.
This value is known as the "sparse element" of S, or the "zero" element
of S.
It happens to be 0 in the case of S, but need not be 0 always.
We can measure the size of the storage occupied by an array
with the built-in 7!:5.
We see that the size of S (which the sparse form of D)
is smaller than the size D itself:
| 7!:5 <'S' |
7!:5 <'D' |
| 384 |
2048 |
30.3 Inspecting A Sparse Array
There is a useful function datatype in the standard library.
It shows the type of its argument.
| datatype D |
datatype S |
| integer |
sparse integer |
Recall that the built verb 3!:0 also gives the type of its argument.
For a sparse array, the possible types reported by 3!:0 are
| 1024 | sparse boolean |
| 2048 | sparse character |
| 4096 | sparse integer |
| 8192 | sparse floating point |
| 16384 | sparse complex |
| 32768 | sparse boxed |
If we display S in the usual way , we see, not the familiar representation of a matrix,
but instead
a list of index-value pairs, one pair for each (in this example)
non-zero element.
S
2 2 | 2
3 6 | 3
4 4 | 4
This display does not show that the sparse element of S is in fact integer zero.
To show this, we can extract the sparse element with the verb 3 & $. .
| se =: 3 $. S |
datatype se |
| 0 |
integer |
If we now compute a new matrix from S
T =: S + 5
we see that T is sparse, and the sparse element of T is not zero but 5
| T |
3 $. T |
2 2 | 7
3 6 | 8
4 4 | 9 |
5 |
Another way to view a sparse array
is simply to convert it to dense with 0 & $.
view =: 0 & $.
| T |
view T |
2 2 | 7
3 6 | 8
4 4 | 9 |
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
5 5 7 5 5 5 5 5 5 5 5 5 5 5 5 5
5 5 5 5 5 5 8 5 5 5 5 5 5 5 5 5
5 5 5 5 9 5 5 5 5 5 5 5 5 5 5 5
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 |
30.4 Computing with Sparse Arrays
Computations with sparse arrays are pretty much the same as
with dense arrays, except that they tend to produce sparse arrays
as results. We saw this with S+5 above. Here is another example.
Summing over T produces a vector of column-sums which is sparse
] V =: +/ T
2 | 82
4 | 84
6 | 83
but the "zero" element of V is the sum of a column of "zero" elements
of T
3 $. V
80
At the time of writing, there are still some limitations on what
can be done with sparse arrays compared with dense arrays.
See the Dictionary under $. for more information.
30.5 Constructing A Sparse Array
At this point it will be helpful to define a few terms.
First note that, according to context,
the numerals 0 or 1 or 0.0 or 1.0
could be valid as boolean or integer or real. However
in the absence of any context the J system takes them all to be in fact
boolean.
| datatype 0 |
datatype 1 |
datatype 0.0 |
datatype 1.0 |
| boolean |
boolean |
boolean |
boolean |
It will be useful to define some values of unambiguous type.
| INTEGERZERO =: 3 - 3 |
datatype INTEGERZERO |
| 0 |
integer |
| INTEGERONE =: 3 - 2 |
datatype INTEGERONE |
| 1 |
integer |
| REALZERO =: 0.0*0.1 |
datatype REALZERO |
| 0 |
floating |
| REALONE =: ^ 0 |
datatype REALONE |
| 1 |
floating |
Returning now to sparse arrays, the recommended method of constructing them
is to begin by making an empty array of
the required shape and type, but with no actual data.
An empty array is built by evaluating the expression
1 $. shape;axes;zero
where
If zero is omitted the default is REALZERO.
If both axes and zero are omitted, the default is all axes sparse
and REALZERO.
So to build a 6 by 6 matrix, sparse in all dimensions (that is, on axis 0 and axis 1),
of type integer with "zero" element of 0 we can write:
U =: 1 $. 6 6 ; 0 1; INTEGERZERO
At this point, U is empty, that is, all "zero",
so displays as nothing:
U
Populate it by inserting a few non-zero elements into it
U =: 4 5 6 7 ( 0 0 ; 1 1; 2 2; 3 3) } U
and check that U is what we expect by viewing it:
view U
4 0 0 0 0 0
0 5 0 0 0 0
0 0 6 0 0 0
0 0 0 7 0 0
0 0 0 0 0 0
0 0 0 0 0 0
30.6 Sparse and Dense Axes
An array may be sparse on some axes and dense on others.
In the following example W is sparse on its first axis
and dense on its second, because
its list of sparse axes is just 0
saw =: ,0 NB. sparse axes for W
W =: 1 $. 3 5; saw ; INTEGERZERO
W =: 4 5 6 (0 1; 0 2; 1 3) } W
It looks as expected:
view W
0 4 5 0 0
0 0 0 6 0
0 0 0 0 0
but we see that it is stored as two dense rows only:
W
0 | 0 4 5 0 0
1 | 0 0 0 6 0
Compare with an array sparse on second axis axis only,
because its list of sparse axes is 1
saz=: ,1 NB. sparse axes for Z
Z =: 1 $. 3 5; saz; INTEGERZERO
Z =: 4 5 6 (0 1; 0 2; 1 3) } Z
Z looks just like W
view Z
0 4 5 0 0
0 0 0 6 0
0 0 0 0 0
but we see it is stored as three dense colums.
Z
1 | 4 0 0
2 | 5 0 0
3 | 0 6 0
30.7 Deconstructing a Sparse Array
As we noted above, if we display U itself, we see, not the familiar representation of a matrix,
but instead
a list of index-value pairs, one pair for each non-zero
element.
U
0 0 | 4
1 1 | 5
2 2 | 6
3 3 | 7
We can extract the index from each pair to get what is
called the index-matrix of U. This is an ordinary dense array
4 $. U
0 0
1 1
2 2
3 3
To extract the value from each pair
5 $. U
4 5 6 7
As we noted above, 0 & $. will produce a dense array
from a sparse:
0 $. U
4 0 0 0 0 0
0 5 0 0 0 0
0 0 6 0 0 0
0 0 0 7 0 0
0 0 0 0 0 0
0 0 0 0 0 0
30.8 Sparse Array From Relation
Next we look at representing data as a sparse array
as an alternative to representing data as a relation (that is,
a table).
The point is that the sparse array may be more convenient
than the relation for some computations with the data.
Thus we are interested in converting between sparse arrays and relations.
For example, suppose that a given relation R represents
sales of various commodities in various cities
'Pa Qu Ro Sy' =: s: ' Paris Quebec Rome Sydney'
'Ap Ba Ch Da' =: s: ' Apples Bananas Cherries Damsons'
R =: (". ;. _2) 0 : 0
Ap ; Pa; 99
Ap ; Qu ; 50
Ba ; Qu ; 10
Ch ; Ro ; 19
Da ; Sy ; 110
Da ; Pa ; 88
)
R
+---------+-------+---+
|`Apples |`Paris |99 |
+---------+-------+---+
|`Apples |`Quebec|50 |
+---------+-------+---+
|`Bananas |`Quebec|10 |
+---------+-------+---+
|`Cherries|`Rome |19 |
+---------+-------+---+
|`Damsons |`Sydney|110|
+---------+-------+---+
|`Damsons |`Paris |88 |
+---------+-------+---+
We can convert the relation R to a sparse array as follows.
Firstly, we need to establish the domain -the set of all possible values -
of the first column. It can be computed from R :
] Fru =: > ~. 0 { |: R
`Apples `Bananas `Cherries `Damsons
Similarly for the domain of the second column:
] Cit =: > ~. 1 { |: R
`Paris `Quebec `Rome `Sydney
Now the first column converted to indices into its domain:
] r =: Fru i. > 0 { |: R
0 0 1 2 3 3
Similarly for the second column:
] c =: Cit i. > 1 { |: R
0 1 1 2 3 0
and the values from the third
] v =: > 2 { |: R
99 50 10 19 110 88
Now we build an empty sparse array of dimensions #Fru by #Cit .
By default the sparse axes will be 0 and 1 and the "zero" element will be REALZERO .
The function 1&$. produces the empty array.
A =: (1 & $.) (#Fru) , (#Cit)
Insert the values by amending in the ordinary way:
A =: v (<"1 r,.c) } A
and check we have what we expect:
view A
99 50 0 0
0 10 0 0
0 0 19 0
88 0 0 110
To display A with labelling of rows and columns,
the list of row-labels is Fru computed above,
and the list of column-labels is Cit :
(a:, <"0 Cit), (<"0 Fru) ,. (<"0 view A)
+---------+------+-------+-----+-------+
| |`Paris|`Quebec|`Rome|`Sydney|
+---------+------+-------+-----+-------+
|`Apples |99 |50 |0 |0 |
+---------+------+-------+-----+-------+
|`Bananas |0 |10 |0 |0 |
+---------+------+-------+-----+-------+
|`Cherries|0 |0 |19 |0 |
+---------+------+-------+-----+-------+
|`Damsons |88 |0 |0 |110 |
+---------+------+-------+-----+-------+
Now we have finished producing the sparse array
from the original relation, so we can can compute with our
data as an array.
For example, total value of sales for each city is given by:
+/ A
0 | 187
1 | 60
2 | 19
3 | 110
This is sparse, so taking the usual view :
view +/ A
187 60 19 110
30.9 Relation from Sparse Array
To complete the circle, we look next at how
to produce a relation from a sparse array, A for example.
A
0 0 | 99
0 1 | 50
1 1 | 10
2 2 | 19
3 0 | 88
3 3 | 110
The first step is to get the index-matrix for the non-zero elements.
] INDS =: 4 $. A
0 0
0 1
1 1
2 2
3 0
3 3
and next the values.
] VALS =: 5 $. A
99 50 10 19 88 110
The first column of the relation we produce by indexing
the domain Fru which we computed above.
The second column is produced similarly from Cit.
] c0 =: (0 { |: INDS) { Fru
`Apples `Apples `Bananas `Cherries `Damsons `Damsons
] c1 =: (1 { |: INDS) { Cit
`Paris `Quebec `Quebec `Rome `Paris `Sydney
So finally we see that the relation recovered from the sparse array is
(<"0 c0) ,. (<"0 c1) ,. (<"0 VALS)
+---------+-------+---+
|`Apples |`Paris |99 |
+---------+-------+---+
|`Apples |`Quebec|50 |
+---------+-------+---+
|`Bananas |`Quebec|10 |
+---------+-------+---+
|`Cherries|`Rome |19 |
+---------+-------+---+
|`Damsons |`Paris |88 |
+---------+-------+---+
|`Damsons |`Sydney|110|
+---------+-------+---+
This is the end of Chapter 30
|


logs requests and responses in their serialized and deserialized forms.
deactivated by default.
Note that this a crude logging system, with no levels, targets etc. like Log4j for example. It is as such to be used for development purposes, but not for production
Located in /Amfphp/Plugins/AmfphpLogger/AmfphpLogger.php (line 23)
constructor.
logs the exception and the packet that caused it
logs the deserialized request
logs the deserialized response
logs the serialized incoming packet
logs the deserialized incoming packet
Documentation generated on Tue, 29 May 2012 23:42:00 +0200 by phpDocumentor 1.4.3


Speech Processing¶
ext_mfcc_feature¶
-
pyasv.speech_processing.
ext_mfcc_feature
(url_path)[source]¶ This function is used for extract MFCC feature of a dataset.
Parameters: - url_path :
str
The path of the ‘PATH’ file.
Returns: - fbank :
list
The feature array. each frame concat with the frame before and after it.
- label :
list
The label of fbank feature.
- url_path :
ext_fbank_feature¶
-
pyasv.speech_processing.
ext_fbank_feature
(url_path)[source]¶ This function is used for extract features of one dataset.
Parameters: - url_path :
str
The path of the ‘PATH’ file.
Returns: - fbank :
list
The feature array. each frame concat with the frame before and after it.
- label :
list
The label of fbank feature.
Notes
Changeable concat size is in the todolist
- url_path :
Note
The file contain the path to all audio and its number in the dataset.
The contents of the file should be as follows:
xxxxx/your_data_path/1_1.wav 0
xxxxx/your_data_path/1_2.wav 0
xxxxx/your_data_path/2_1.wav 1
calc_fbank¶
calc_cqcc¶
slide_windows¶
cqcc_resample¶
-
pyasv.speech_processing.
cqcc_resample
(s, fs_orig, fs_new, axis=0)[source]¶ implement the resample operation of CQCC
Parameters: - s :
np.ndarray
the input spectrogram.
- fs_orig :
int
origin sample rate
- fs_new :
int
new sample rate
- axis :
int
the resample axis
Returns: - spec_res :
np.ndarray
spectrogram after resample
- s :


Ruby has a variety of ways to control execution. All the expressions described here return a value.
For the tests in these control expressions, nil
and
false
are false-values and true
and any other
object are true-values. In this document “true” will mean “true-value” and
“false” will mean “false-value”.
if
Expression¶ ↑The simplest if
expression has two parts, a “test” expression
and a “then” expression. If the “test” expression evaluates to a true then
the “then” expression is evaluated.
Here is a simple if statement:
if true then puts "the test resulted in a true-value" end
This will print “the test resulted in a true-value”.
The then
is optional:
if true puts "the test resulted in a true-value" end
This document will omit the optional then
for all expressions
as that is the most common usage of if
.
You may also add an else
expression. If the test does not
evaluate to true the else
expression will be executed:
if false puts "the test resulted in a true-value" else puts "the test resulted in a false-value" end
This will print “the test resulted in a false-value”.
You may add an arbitrary number of extra tests to an if expression using
elsif
. An elsif
executes when all tests above
the elsif
are false.
a = 1 if a == 0 puts "a is zero" elsif a == 1 puts "a is one" else puts "a is some other value" end
This will print “a is one” as 1
is not equal to
0
. Since else
is only executed when there are no
matching conditions.
Once a condition matches, either the if
condition or any
elsif
condition, the if
expression is complete
and no further tests will be performed.
Like an if
, an elsif
condition may be followed by
a then
.
In this example only “a is one” is printed:
a = 1 if a == 0 puts "a is zero" elsif a == 1 puts "a is one" elsif a >= 1 puts "a is greater than or equal to one" else puts "a is some other value" end
The tests for if
and elsif
may have side-effects.
The most common use of side-effect is to cache a value into a local
variable:
if a = object.some_value # do something to a end
The result value of an if
expression is the last value
executed in the expression.
You may also write a if-then-else expression using ?
and
:
. This ternary if:
input_type = gets =~ /hello/i ? "greeting" : "other"
Is the same as this if
expression:
input_type = if gets =~ /hello/i "greeting" else "other" end
While the ternary if is much shorter to write than the more verbose form, for readability it is recommended that the ternary if is only used for simple conditionals. Also, avoid using multiple ternary conditions in the same expression as this can be confusing.
unless
Expression¶ ↑The unless
expression is the opposite of the if
expression. If the value is false, the “then” expression is executed:
unless true puts "the value is a false-value" end
This prints nothing as true is not a false-value.
You may use an optional then
with unless
just
like if
.
Note that the above unless
expression is the same as:
if not true puts "the value is a false-value" end
Like an if
expression you may use an else
condition with unless
:
unless true puts "the value is false" else puts "the value is true" end
This prints “the value is true” from the else
condition.
You may not use elsif
with an unless
expression.
The result value of an unless
expression is the last value
executed in the expression.
if
and unless
¶ ↑if
and unless
can also be used to modify an
expression. When used as a modifier the left-hand side is the “then”
statement and the right-hand side is the “test” expression:
a = 0 a += 1 if a.zero? p a
This will print 1.
a = 0 a += 1 unless a.zero? p a
This will print 0.
While the modifier and standard versions have both a “test” expression and a “then” statement, they are not exact transformations of each other due to parse order. Here is an example that shows the difference:
p a if a = 0.zero?
This raises the NameError “undefined local variable or method `a'”.
When ruby parses this expression it first encounters a
as a
method call in the “then” expression, then later it sees the assignment to
a
in the “test” expression and marks a
as a local
variable.
When running this line it first executes the “test” expression, a =
0.zero?
.
Since the test is true it executes the “then” expression, p a
.
Since the a
in the body was recorded as a method which does
not exist the NameError is raised.
The same is true for unless
.
case
Expression¶ ↑The case
expression can be used in two ways.
The most common way is to compare an object against multiple patterns. The patterns are matched using the +===+ method which is aliased to +==+ on Object. Other classes must override it to give meaningful behavior. See Module#=== and Regexp#=== for examples.
Here is an example of using case
to compare a String against a pattern:
case "12345" when /^1/ puts "the string starts with one" else puts "I don't know what the string starts with" end
Here the string "12345"
is compared with
/^1/
by calling /^1/ === "12345"
which
returns true
. Like the if
expression, the first
when
that matches is executed and all other matches are
ignored.
If no matches are found, the else
is executed.
The else
and then
are optional, this
case
expression gives the same result as the one above:
case "12345" when /^1/ puts "the string starts with one" end
You may place multiple conditions on the same when
:
case "2" when /^1/, "2" puts "the string starts with one or is '2'" end
Ruby will try each condition in turn, so first /^1/ ===
"2"
returns false
, then "2"
=== "2"
returns true
, so “the string starts
with one or is '2'” is printed.
You may use then
after the when
condition. This
is most frequently used to place the body of the when
on a
single line.
case a when 1, 2 then puts "a is one or two when 3 then puts "a is three" else puts "I don't know what a is" end
The other way to use a case
expression is like an if-elsif
expression:
a = 2 case when a == 1, a == 2 puts "a is one or two" when a == 3 puts "a is three" else puts "I don't know what a is" end
Again, the then
and else
are optional.
The result value of a case
expression is the last value
executed in the expression.
while
Loop¶ ↑The while
loop executes while a condition is true:
a = 0 while a < 10 do p a a += 1 end p a
Prints the numbers 0 through 10. The condition a < 10
is
checked before the loop is entered, then the body executes, then the
condition is checked again. When the condition results in false the loop
is terminated.
The do
keyword is optional. The following loop is equivalent
to the loop above:
while a < 10 p a a += 1 end
The result of a while
loop is nil
unless
break
is used to supply a value.
until
Loop¶ ↑The until
loop executes while a condition is false:
a = 0 until a > 10 do p a a += 1 end p a
This prints the numbers 0 through 11. Like a while loop the condition
a > 10
is checked when entering the loop and each time the
loop body executes. If the condition is false the loop will continue to
execute.
Like a while
loop, the do
is optional.
Like a while
loop, the result of an until
loop is
nil unless break
is used.
for
Loop¶ ↑The for
loop consists of for
followed by a
variable to contain the iteration argument followed by in
and
the value to iterate over using each. The do
is optional:
for value in [1, 2, 3] do puts value end
Prints 1, 2 and 3.
Like while
and until
, the do
is
optional.
The for
loop is similar to using each, but does not create a
new variable scope.
The result value of a for
loop is the value iterated over
unless break
is used.
The for
loop is rarely used in modern ruby programs.
while
and until
¶ ↑Like if
and unless
, while
and
until
can be used as modifiers:
a = 0 a += 1 while a < 10 p a # prints 10
until
used as a modifier:
a = 0 a += 1 until a > 10 p a # prints 11
You can use begin
and end
to create a
while
loop that runs the body once before the condition:
a = 0 begin a += 1 end while a < 10 p a # prints 10
If you don't use rescue
or ensure
, Ruby
optimizes away any exception handling overhead.
break
Statement¶ ↑Use break
to leave a block early. This will stop iterating
over the items in values
if one of them is even:
values.each do |value| break if value.even? # ... end
You can also terminate from a while
loop using
break
:
a = 0 while true do p a a += 1 break if a < 10 end p a
This prints the numbers 0 and 1.
break
accepts a value that supplies the result of the
expression it is “breaking” out of:
result = [1, 2, 3].each do |value| break value * 2 if value.even? end p result # prints 4
next
Statement¶ ↑Use next
to skip the rest of the current iteration:
result = [1, 2, 3].map do |value| next if value.even? value * 2 end p result # prints [2, nil, 6]
next
accepts an argument that can be used as the result of the
current block iteration:
result = [1, 2, 3].map do |value| next value if value.even? value * 2 end p result # prints [2, 2, 6]
redo
Statement¶ ↑Use redo
to redo the current iteration:
result = [] while result.length < 10 do result << result.length redo if result.last.even? result << result.length + 1 end p result
This prints [0, 1, 3, 3, 5, 5, 7, 7, 9, 9, 11]
In Ruby 1.8, you could also use retry
where you used
redo
. This is no longer true, now you will receive a SyntaxError when you use
retry
outside of a rescue
block. See Exceptions
for proper usage of retry
.
Ruby's grammar differentiates between statements and expressions. All expressions are statements (an expression is a type of statement), but not all statements are expressions. Some parts of the grammar accept expressions and not other types of statements, which causes code that looks similar to be parsed differently.
For example, when not used as a modifier, if
,
else
, while
, until
, and
begin
are expressions (and also statements). However, when
used as a modifier, if
, else
, while
,
until
and rescue
are statements but not
expressions.
if true; 1 end # expression (and therefore statement) 1 if true # statement (not expression)
Statements that are not expressions cannot be used in contexts where an expression is expected, such as method arguments.
puts( 1 if true ) #=> SyntaxError
You can wrap a statement in parentheses to create an expression.
puts((1 if true)) #=> 1
If you put a space between the method name and opening parenthesis, you do not need two sets of parentheses.
puts (1 if true) #=> 1, because of optional parentheses for method
This is because this is parsed similar to a method call without parentheses. It is equivalent to the following code, without the creation of a local variable:
x = (1 if true) p x
In a modifier statement, the left-hand side must be a statement and the right-hand side must be an expression.
So in a if b rescue c
, because b rescue c
is a
statement that is not an expression, and therefore is not allowed as the
right-hand side of the if
modifier statement, the code is
necessarily parsed as (a if b) rescue c
.
This interacts with operator precedence in such a way that:
stmt if v = expr rescue x stmt if v = expr unless x
are parsed as:
stmt if v = (expr rescue x) (stmt if v = expr) unless x
This is because modifier rescue
has higher precedence than
=
, and modifier if
has lower precedence than
=
.
The flip-flop is a rarely seen conditional expression. It's primary
use is for processing text from ruby one-line programs used with ruby
-n
or ruby -p
.
The form of the flip-flop is an expression that indicates when the
flip-flop turns on, ..
(or ...
), then an
expression that indicates when the flip-flop will turn off. While the
flip-flop is on it will continue to evaluate to true
, and
false
when off.
Here is an example:
selected = [] 0.upto 10 do |value| selected << value if value==2..value==8 end p selected # prints [2, 3, 4, 5, 6, 7, 8]
In the above example, the on condition is n==2
. The flip-flop
is initially off (false) for 0 and 1, but becomes on (true) for 2 and
remains on through 8. After 8 it turns off and remains off for 9 and 10.
The flip-flop must be used inside a conditional such as if
,
while
, unless
, until
etc. including
the modifier forms.
When you use an inclusive range (..
), the off condition is
evaluated when the on condition changes:
selected = [] 0.upto 5 do |value| selected << value if value==2..value==2 end p selected # prints [2]
Here, both sides of the flip-flop are evaluated so the flip-flop turns on
and off only when value
equals 2. Since the flip-flop turned
on in the iteration it returns true.
When you use an exclusive range (...
), the off condition is
evaluated on the following iteration:
selected = [] 0.upto 5 do |value| selected << value if value==2...value==2 end p selected # prints [2, 3, 4, 5]
Here, the flip-flop turns on when value
equals 2, but
doesn't turn off on the same iteration. The off condition isn't
evaluated until the following iteration and value
will never
be two again.


@(message: String)
If you are a PCD storage provider you can register yourself here
Download Our Public Key


THE CREATORS
MICHELLE WU IS A VISUAL DESIGNER AND BOOK BINDER WHO CURRENTLY WORKS AT GOOGLE BRAND STUDIO IN SF. SHE LOVES TO MAKE BOOKS AND IS PASSIONATE ABOUT INVESTIGATING THE INTERSECTIONS OF IDENTITY AND CULTURE.
YOU CAN SEE HER MOST CURRENT WORKS HERE.
VANESSA YANG IS A VISUAL DESIGNER LIVING IN LOS ANGELES.


Welcome to the Flu Shot Finder for {{site.locality}}. If your device has GPS, you may click on the Find Me button to see locations near you.  Click on All, Next 7 Days, or On A Day of the week to highlight locations available on a certain day. Blue map locations offer free flu shots for anyone six months of age or older.


FormalDateFinder.com is not yet fully operational. Coming soon!
FormalDateFinder.com
View Upcoming Events
Register an Event
Login
{% block content %} {% endblock %}


This app was designed to transform text messages from spacebrew. It listens for incoming messages in one or all inlets. If an incoming message is matched to a key message, then the associated mapped message is sent via one or all outlets. A mapped message can also be sent by pressing the "send me" button.


SUNMARK Z SLEEP- diphenhydramine hydrochloride solution
McKesson
Disclaimer: Most OTC drugs are not reviewed and approved by FDA, however they may be marketed if they comply with applicable regulations and policies. FDA has not evaluated whether this product complies.
Active ingredient (in each 30 mL dose cup)
Diphenhydramine HCl 50 mg
Purpose
Nighttime sleep-aid
Uses
- •
- for the relief of occasional sleeplessness
- •
- reduces time to fall asleep if you have difficulty falling asleep
Warnings
Do not use
- •
- for children under 12 years of age
- •
- with any other product containing diphenhydramine, even one used on skin
- •
- with other drugs that cause drowsiness such as antihistamines and nighttime cold/flu products
- •
- with other Nighttime products
Ask a doctor before use if you have
- •
- a breathing problem such as emphysema or chronic bronchitis
- •
- glaucoma
- •
- difficulty in urination due to an enlargement of the prostate gland
Ask a doctor or pharmacist before use if you are
taking sedatives or tranquilizers
When using this product
- •
- avoid alcoholic beverages
- •
- drowsiness will occur
- •
- do not drive a motor vehicle or operate machinery
Stop use and ask a doctor if
sleeplessness persists continuously for more than 2 weeks. Insomnia may be a symptom of serious underlying medical illness.
If pregnant or breast-feeding,
ask a health professional before use.
Keep out of reach of children.
Overdose warning: Taking more than directed can cause serious health problems. In case of overdose, get medical help or contact a Poison Control Center right away. (1-800-222-1222)
Directions
- •
- take only one dose per day (24 hours) – see Overdose warning
- •
- use dose cup
-
- adults & children 12 yrs & over
|
-
- 30 mL at bed time if needed or as directed by a doctor
|
-
- children under 12 yrs
|
-
- do not use
|
Other information
- •
- each 30 mL dose cup contains: sodium 20 mg
- •
- store at 20-25°C (68-77°F)
- •
- protect from light. Does not meet USP <671>.
Inactive Ingredients
alcohol, anhydrous citric acid, FD&C blue #1, FD&C red #40, flavor, high fructose corn syrup, poloxamer 407, propylene glycol, purified water, saccharin sodium, sodium benzoate, sodium citrate
Questions or comments?
1-800-719-9260
Package/Label Principal Display Panel
COMPARE TO VICKS® ZZZQUIL® ACTIVE INGREDIENT
z-sleep®
Nighttime Sleep-Aid
Non-habit forming
not for treat cold or flu
see warnings
ALCOHOL 10%
DOCTOR RECOMMENDED #1 sleep aid active ingredient
Diphenhydramine HCl
50 mg per 30 mL
BERRY FLAVOR
GLUTEN FREE
6 FL OZ (177 mL)


crmAPI.log
in your code.
ctrl
3 times in a row quickly.
@url 'http://example.com';to run certain CSS only on specified url for any code following this statement. Calling
@urlend;will stop this from applying to the code below it. You can combine multiple
@urlstatements to run on multiple sites, so calling
@url 'example.com'; @url 'google.com';runs the code below on both sites. If for example you want any page's background-color to be black except for one website, you can use
@urlto give that page a different background color. You can use regular expressions as long as you wrap them in brackets.


Sorry, ID was not found in our database, or there are no books/friends associated with this user, please try another!


Date: Fri Sep 25 2015 02:00:00 GMT+0200 (CEST)
Have I greeted the world? Just to be sure:
Hello world!
Date: Sat Aug 15 2015 02:00:00 GMT+0200 (CEST)
No July post, sorry... it was too hot. August is hot too.
Date: Sun Jun 28 2015 02:00:00 GMT+0200 (CEST)
June is almost passed, i'm waiting for July.


|
chigraph
master
Systems programming language written for beginners in LLVM
|
this is an AST-like representation of a function in a graph It is used for IDE-like behavior, codegen, and JSON generation. More...
#include <chig/GraphFunction.hpp>
Public Member Functions | |
| GraphFunction (GraphModule &mod, std::string name, std::vector< NamedDataType > dataIns, std::vector< NamedDataType > dataOuts, std::vector< std::string > execIns, std::vector< std::string > execOuts) | |
| Construct a graph–don't call this directly use GraphModule::getorCreateFunction. More... | |
| GraphFunction (const GraphFunction &)=delete | |
| GraphFunction (GraphFunction &&)=delete | |
| ~GraphFunction ()=default | |
| Destructor. | |
| Context & | context () const |
| Get the context. More... | |
| Result | createEntryNodeType (std::unique_ptr< NodeType > *toFill) const |
| Create a fresh NodeType for an entry. More... | |
| Result | createExitNodeType (std::unique_ptr< NodeType > *toFill) const |
| Create a fresh NodeType for an exit. More... | |
| const std::string & | description () const |
| Get the description of the function. More... | |
| llvm::FunctionType * | functionType () const |
| Get the LLVM function type for the function. More... | |
| GraphModule & | module () const |
| Get the GraphModule that contains this GraphFunction. More... | |
| std::string | name () const |
| Get the name of the function. More... | |
| GraphFunction & | operator= (const GraphFunction &)=delete |
| GraphFunction & | operator= (GraphFunction &&)=delete |
| void | setDescription (std::string newDesc) |
| Set the description of the function. More... | |
Node Manipulation | |
Functions for mainpulating nodes; getting, adding | |
| std::unordered_map< boost::uuids::uuid, std::unique_ptr< NodeInstance > > & | nodes () |
| Get the nodes in the function Usually called by connectData or connectExec or GraphFunction. More... | |
| const std::unordered_map< boost::uuids::uuid, std::unique_ptr< NodeInstance > > & | nodes () const |
| NodeInstance * | entryNode () const noexcept |
| Gets the node with type lang:entry returns nullptr on failure Also returns nullptr if there are two entry nodes, which is illegal. More... | |
| Result | insertNode (std::unique_ptr< NodeType > type, float x, float y, boost::uuids::uuid id=boost::uuids::random_generator()(), NodeInstance **toFill=nullptr) |
| Add a node to the graph. More... | |
| std::vector< NodeInstance * > | nodesWithType (const boost::filesystem::path &module, boost::string_view name) const noexcept |
| Gets the nodes with a given type. More... | |
| Result | insertNode (const boost::filesystem::path &moduleName, boost::string_view typeName, const nlohmann::json &typeJSON, float x, float y, boost::uuids::uuid id=boost::uuids::random_generator()(), NodeInstance **toFill=nullptr) |
| Add a node to the graph using module, type, and json. More... | |
| Result | removeNode (NodeInstance *nodeToRemove) |
| Remove a node from the function. More... | |
| Result | getOrInsertEntryNode (float x, float y, boost::uuids::uuid id=boost::uuids::random_generator()(), NodeInstance **toFill=nullptr) |
| Creates an entry node if it doesn't already exist, else just return it. More... | |
Data input modifiers | |
| const std::vector< NamedDataType > & | dataInputs () const |
| Get the function data inputs in the format {type, docstring}. More... | |
| void | addDataInput (const DataType &type, std::string name, size_t addBefore=(std::numeric_limits< size_t >::max)()) |
| Add an input to the end of the argument list. More... | |
| void | removeDataInput (size_t idx) |
| Remove an input from the argument list Also removes invalid connections If idx is out of range, this function does nothing. More... | |
| void | renameDataInput (size_t idx, std::string newName) |
| Rename a data input This also updates the entry node If idx is out of range, this function does nothing. More... | |
| void | retypeDataInput (size_t idx, DataType newType) |
| Change the type of a data input This also updates the entry node and disconnects invalid connections. More... | |
Data output modifiers | |
| const std::vector< NamedDataType > & | dataOutputs () const |
| Get the function data outputs in the format {type, docstring}. More... | |
| void | addDataOutput (const DataType &type, std::string name, size_t addBefore=(std::numeric_limits< size_t >::max)()) |
| Add an data output to the end of the argument list. More... | |
| void | removeDataOutput (size_t idx) |
| Remove an data output from the argument list Also removes invalid connections If idx is out of range, this function does nothing. More... | |
| void | renameDataOutput (size_t idx, std::string newName) |
| Modify an data output (change it's type and docstring) More... | |
| void | retypeDataOutput (size_t idx, DataType newType) |
| Change the type of a data output This also updates all exit nodes and disconnects invalid connections. More... | |
Exec input modifiers | |
| const std::vector< std::string > & | execInputs () const |
| Get the function exec inputs. More... | |
| void | addExecInput (std::string name, size_t addBefore=(std::numeric_limits< size_t >::max)()) |
| Add an exec input to the end of the argument list. More... | |
| void | removeExecInput (size_t idx) |
| Remove an exec input from the argument list If idx is out of range, this function does nothing. More... | |
| void | renameExecInput (size_t idx, std::string name) |
| Change the name for an exec input If idx is out of range, this function does nothing. More... | |
Exec output modifiers | |
Getters/modifers for exec output | |
| const std::vector< std::string > & | execOutputs () const |
| Get the function exec outputs. More... | |
| void | addExecOutput (std::string name, size_t addBefore=(std::numeric_limits< size_t >::max)()) |
| Add an exec output to the end of the argument list. More... | |
| void | removeExecOutput (size_t idx) |
| Remove an exec output from the argument list If idx is out of range, this function does nothing. More... | |
| void | renameExecOutput (size_t idx, std::string name) |
| Rename an exec output If idx is out of range, this function does nothing. More... | |
Local Variable Manipulation functions | |
| const std::vector< NamedDataType > & | localVariables () const |
| Get the local variables. More... | |
| NamedDataType | localVariableFromName (boost::string_view name) const |
| Get a local varaible by name. More... | |
| NamedDataType | getOrCreateLocalVariable (std::string name, DataType type, bool *inserted=nullptr) |
| Create a new local varaible in the module. More... | |
| bool | removeLocalVariable (boost::string_view name) |
| Remove a local variable from the function by name. More... | |
| void | renameLocalVariable (std::string oldName, std::string newName) |
| Rename a local variable. More... | |
| void | retypeLocalVariable (boost::string_view name, DataType newType) |
| Set a new type to a local variable. More... | |
this is an AST-like representation of a function in a graph It is used for IDE-like behavior, codegen, and JSON generation.
Definition at line 27 of file GraphFunction.hpp.
| chig::GraphFunction::GraphFunction | ( | GraphModule & | mod, |
| std::string | name, | ||
| std::vector< NamedDataType > | dataIns, | ||
| std::vector< NamedDataType > | dataOuts, | ||
| std::vector< std::string > | execIns, | ||
| std::vector< std::string > | execOuts | ||
| ) |
Construct a graph–don't call this directly use GraphModule::getorCreateFunction.
| mod | The owning module |
| name | The name of the function |
| dataIns | The data inputs to the function |
| dataOuts | The data outputs of the function |
| execIns | The exec inputs to the function |
| execOuts | The exec outputs to the function |
Definition at line 20 of file GraphFunction.cpp.
References name().
| void chig::GraphFunction::addDataInput | ( | const DataType & | type, |
| std::string | name, | ||
| size_t | addBefore = (std::numeric_limits<size_t>::max)() |
||
| ) |
Add an input to the end of the argument list.
| type | The new input type |
| name | The name of the input (just for documentation) |
| addBefore | The input ID to add before, default is end |
Definition at line 190 of file GraphFunction.cpp.
Referenced by dataInputs().
| void chig::GraphFunction::addDataOutput | ( | const DataType & | type, |
| std::string | name, | ||
| size_t | addBefore = (std::numeric_limits<size_t>::max)() |
||
| ) |
Add an data output to the end of the argument list.
| type | The new output type |
| name | The name of the output (just for documentation) |
| addBefore | The output to add before, default is end |
Definition at line 214 of file GraphFunction.cpp.
Referenced by dataOutputs().
| void chig::GraphFunction::addExecInput | ( | std::string | name, |
| size_t | addBefore = (std::numeric_limits<size_t>::max)() |
||
| ) |
Add an exec input to the end of the argument list.
| name | The name of the input (just for documentation) |
| addBefore | the input to add after |
Definition at line 259 of file GraphFunction.cpp.
Referenced by execInputs().
| void chig::GraphFunction::addExecOutput | ( | std::string | name, |
| size_t | addBefore = (std::numeric_limits<size_t>::max)() |
||
| ) |
Add an exec output to the end of the argument list.
| name | The name of the output (just for documentation) |
| addBefore | The output to add after |
Definition at line 279 of file GraphFunction.cpp.
Referenced by execOutputs().
|
inline |
Get the context.
Definition at line 311 of file GraphFunction.hpp.
Referenced by chig::compileFunction(), createEntryNodeType(), createExitNodeType(), functionType(), insertNode(), and chig::jsonToGraphFunction().
Create a fresh NodeType for an entry.
| toFill | The NodeType pointer to fill |
Definition at line 137 of file GraphFunction.cpp.
References context(), dataInputs(), execInputs(), and chig::Context::nodeTypeFromModule().
Referenced by getOrInsertEntryNode(), nodes(), and renameExecOutput().
Create a fresh NodeType for an exit.
| toFill | The NodeType pointer to fill |
Definition at line 155 of file GraphFunction.cpp.
References context(), dataOutputs(), execOutputs(), and chig::Context::nodeTypeFromModule().
Referenced by nodes(), and renameExecOutput().
|
inline |
Get the function data inputs in the format {type, docstring}.
Definition at line 144 of file GraphFunction.hpp.
References addDataInput(), removeDataInput(), renameDataInput(), and retypeDataInput().
Referenced by chig::compileFunction(), createEntryNodeType(), entryNode(), functionType(), and chig::graphFunctionToJson().
|
inline |
Get the function data outputs in the format {type, docstring}.
Definition at line 179 of file GraphFunction.hpp.
References addDataOutput(), removeDataOutput(), renameDataOutput(), and retypeDataOutput().
Referenced by chig::compileFunction(), createExitNodeType(), functionType(), and chig::graphFunctionToJson().
|
inline |
Get the description of the function.
Definition at line 304 of file GraphFunction.hpp.
Referenced by chig::graphFunctionToJson().
|
noexcept |
Gets the node with type lang:entry returns nullptr on failure Also returns nullptr if there are two entry nodes, which is illegal.
Definition at line 34 of file GraphFunction.cpp.
References dataInputs(), execInputs(), and nodesWithType().
Referenced by chig::compileFunction(), getOrInsertEntryNode(), nodes(), and chig::validateFunctionNodeInputs().
|
inline |
Get the function exec inputs.
Definition at line 215 of file GraphFunction.hpp.
References addExecInput(), removeExecInput(), and renameExecInput().
Referenced by createEntryNodeType(), entryNode(), and chig::graphFunctionToJson().
|
inline |
Get the function exec outputs.
Definition at line 241 of file GraphFunction.hpp.
References addExecOutput(), removeExecOutput(), and renameExecOutput().
Referenced by createExitNodeType(), and chig::graphFunctionToJson().
| llvm::FunctionType * chig::GraphFunction::functionType | ( | ) | const |
Get the LLVM function type for the function.
Definition at line 241 of file GraphFunction.cpp.
References context(), dataInputs(), and dataOutputs().
Referenced by chig::compileFunction(), and nodes().
| NamedDataType chig::GraphFunction::getOrCreateLocalVariable | ( | std::string | name, |
| DataType | type, | ||
| bool * | inserted = nullptr |
||
| ) |
Create a new local varaible in the module.
| name | The name of the local variable |
| type | The type of the local |
| inserted | True if the local varaiable was new, optional |
Definition at line 329 of file GraphFunction.cpp.
References localVariableFromName().
Referenced by chig::jsonToGraphFunction(), and localVariables().
| Result chig::GraphFunction::getOrInsertEntryNode | ( | float | x, |
| float | y, | ||
| boost::uuids::uuid | id = boost::uuids::random_generator()() , |
||
| NodeInstance ** | toFill = nullptr |
||
| ) |
Creates an entry node if it doesn't already exist, else just return it.
| x | The x coordinate of the new entry, or changes the existing entry node to be at this X location |
| y | The y coordinate of the new entry, or changes the existing entry node to be at this Y location |
| id | The ID of the node, disregarded if there is already an entry |
| toFill | The NodeInstance* to fill, optional |
Definition at line 173 of file GraphFunction.cpp.
References createEntryNodeType(), entryNode(), and insertNode().
Referenced by nodes().
| Result chig::GraphFunction::insertNode | ( | std::unique_ptr< NodeType > | type, |
| float | x, | ||
| float | y, | ||
| boost::uuids::uuid | id = boost::uuids::random_generator()() , |
||
| NodeInstance ** | toFill = nullptr |
||
| ) |
Add a node to the graph.
| type | The type of the node |
| x | The x location of the node |
| y | The y location of the node |
| id | The node ID |
| toFill | The nodeInstance to fill to, optional. |
Definition at line 54 of file GraphFunction.cpp.
References chig::Result::addEntry(), and nodes().
Referenced by getOrInsertEntryNode(), insertNode(), chig::jsonToGraphFunction(), and nodes().
| Result chig::GraphFunction::insertNode | ( | const boost::filesystem::path & | moduleName, |
| boost::string_view | typeName, | ||
| const nlohmann::json & | typeJSON, | ||
| float | x, | ||
| float | y, | ||
| boost::uuids::uuid | id = boost::uuids::random_generator()() , |
||
| NodeInstance ** | toFill = nullptr |
||
| ) |
Add a node to the graph using module, type, and json.
| moduleName | The name of the module that typeName is in |
| typeName | The name of the node type in the module with the name moduleName |
| typeJSON | The JSON to be passed to create the type |
| x | The x location of the node |
| y | The y location of the node |
| id | The node ID |
| toFill | The NodeInstance* to fill to, optional |
Definition at line 87 of file GraphFunction.cpp.
References context(), insertNode(), and chig::Context::nodeTypeFromModule().
| NamedDataType chig::GraphFunction::localVariableFromName | ( | boost::string_view | name | ) | const |
Get a local varaible by name.
| name | The name of the variable |
Definition at line 321 of file GraphFunction.cpp.
Referenced by getOrCreateLocalVariable(), and localVariables().
|
inline |
Get the local variables.
Definition at line 266 of file GraphFunction.hpp.
References getOrCreateLocalVariable(), localVariableFromName(), removeLocalVariable(), renameLocalVariable(), and retypeLocalVariable().
Referenced by chig::graphFunctionToJson().
|
inline |
Get the GraphModule that contains this GraphFunction.
Definition at line 317 of file GraphFunction.hpp.
Referenced by chig::compileFunction(), chig::Debugger::nodeFromFrame(), nodes(), nodesWithType(), chig::parseColonPair(), removeLocalVariable(), renameLocalVariable(), and retypeLocalVariable().
|
inline |
Get the name of the function.
Definition at line 314 of file GraphFunction.hpp.
Referenced by chig::compileFunction(), GraphFunction(), chig::graphFunctionToJson(), nodesWithType(), chig::parseColonPair(), and removeLocalVariable().
|
inline |
Get the nodes in the function Usually called by connectData or connectExec or GraphFunction.
Definition at line 55 of file GraphFunction.hpp.
Referenced by chig::graphFunctionToJson(), insertNode(), chig::jsonToGraphFunction(), removeNode(), and chig::validateFunctionConnectionsAreTwoWay().
|
inline |
Definition at line 59 of file GraphFunction.hpp.
References createEntryNodeType(), createExitNodeType(), entryNode(), functionType(), getOrInsertEntryNode(), insertNode(), module(), nodesWithType(), and removeNode().
|
noexcept |
Gets the nodes with a given type.
| module | The module the type is in |
| name | The name of the type |
Definition at line 74 of file GraphFunction.cpp.
References module(), and name().
Referenced by entryNode(), nodes(), removeLocalVariable(), renameExecOutput(), renameLocalVariable(), and retypeLocalVariable().
| void chig::GraphFunction::removeDataInput | ( | size_t | idx | ) |
Remove an input from the argument list Also removes invalid connections If idx is out of range, this function does nothing.
| idx | The index to delete |
Definition at line 199 of file GraphFunction.cpp.
Referenced by dataInputs().
| void chig::GraphFunction::removeDataOutput | ( | size_t | idx | ) |
Remove an data output from the argument list Also removes invalid connections If idx is out of range, this function does nothing.
| idx | The index to delete |
Definition at line 226 of file GraphFunction.cpp.
Referenced by dataOutputs().
| void chig::GraphFunction::removeExecInput | ( | size_t | idx | ) |
Remove an exec input from the argument list If idx is out of range, this function does nothing.
| idx | The index to delete |
Definition at line 269 of file GraphFunction.cpp.
Referenced by execInputs().
| void chig::GraphFunction::removeExecOutput | ( | size_t | idx | ) |
Remove an exec output from the argument list If idx is out of range, this function does nothing.
| idx | The index to delete |
Definition at line 289 of file GraphFunction.cpp.
Referenced by execOutputs().
| bool chig::GraphFunction::removeLocalVariable | ( | boost::string_view | name | ) |
Remove a local variable from the function by name.
| name | The name of the local variable to remove |
Definition at line 344 of file GraphFunction.cpp.
References module(), name(), nodesWithType(), and removeNode().
Referenced by localVariables().
| Result chig::GraphFunction::removeNode | ( | NodeInstance * | nodeToRemove | ) |
Remove a node from the function.
Also disconnect it's connections.
| nodeToRemove | The node to remove |
Definition at line 98 of file GraphFunction.cpp.
References chig::disconnectData(), chig::disconnectExec(), chig::NodeInstance::id(), chig::NodeInstance::inputDataConnections, chig::NodeInstance::inputExecConnections, nodes(), chig::NodeInstance::outputDataConnections, and chig::NodeInstance::outputExecConnections.
Referenced by nodes(), and removeLocalVariable().
| void chig::GraphFunction::renameDataInput | ( | size_t | idx, |
| std::string | newName | ||
| ) |
Rename a data input This also updates the entry node If idx is out of range, this function does nothing.
| idx | The index to rename |
| newName | The new name |
Definition at line 204 of file GraphFunction.cpp.
Referenced by dataInputs().
| void chig::GraphFunction::renameDataOutput | ( | size_t | idx, |
| std::string | newName | ||
| ) |
Modify an data output (change it's type and docstring)
Rename a data output This also updates all exit nodes If idx is out of range, this function does nothing.
| idx | The index to rename |
| newName | The new name |
Definition at line 231 of file GraphFunction.cpp.
Referenced by dataOutputs().
| void chig::GraphFunction::renameExecInput | ( | size_t | idx, |
| std::string | name | ||
| ) |
Change the name for an exec input If idx is out of range, this function does nothing.
| idx | The index to change |
| name | The new name. |
Definition at line 274 of file GraphFunction.cpp.
Referenced by execInputs().
| void chig::GraphFunction::renameExecOutput | ( | size_t | idx, |
| std::string | name | ||
| ) |
Rename an exec output If idx is out of range, this function does nothing.
| idx | The index to change |
| name | The new name. |
Definition at line 294 of file GraphFunction.cpp.
References createEntryNodeType(), createExitNodeType(), and nodesWithType().
Referenced by execOutputs().
| void chig::GraphFunction::renameLocalVariable | ( | std::string | oldName, |
| std::string | newName | ||
| ) |
Rename a local variable.
| oldName | The name of the existing local to change |
| newName | The new name of the local |
Definition at line 364 of file GraphFunction.cpp.
References module(), nodesWithType(), and chig::GraphModule::nodeTypeFromName().
Referenced by localVariables().
| void chig::GraphFunction::retypeDataInput | ( | size_t | idx, |
| DataType | newType | ||
| ) |
Change the type of a data input This also updates the entry node and disconnects invalid connections.
If idx is out of range, this function does nothing.
| idx | The index to retype |
| newType | The new type |
Definition at line 209 of file GraphFunction.cpp.
Referenced by dataInputs().
| void chig::GraphFunction::retypeDataOutput | ( | size_t | idx, |
| DataType | newType | ||
| ) |
Change the type of a data output This also updates all exit nodes and disconnects invalid connections.
If idx is out of range, this function does nothing.
| idx | The index to retype |
| newType | The new type |
Definition at line 236 of file GraphFunction.cpp.
Referenced by dataOutputs().
| void chig::GraphFunction::retypeLocalVariable | ( | boost::string_view | name, |
| DataType | newType | ||
| ) |
Set a new type to a local variable.
| name | The name of the local to change |
| newType | The new type |
Definition at line 402 of file GraphFunction.cpp.
References module(), nodesWithType(), chig::GraphModule::nodeTypeFromName(), and chig::DataType::qualifiedName().
Referenced by localVariables().
|
inline |
Set the description of the function.
| newDesc | The new description |
Definition at line 300 of file GraphFunction.hpp.
Referenced by chig::createGraphFunctionDeclarationFromJson().


Convert raw sequencing files into library counts using bowtie alignment
The script used for this step is fastqgz_to_counts.py, and requires a reference fasta file of the library used in the experiment. Indices for several published libraries are included here, and more can be generated upon request.
2. Generate sgRNA phenotype scores, gene-level scores, and gene-level p-values
This step relies on the script process_experiments.py. This script requires you to first fill out a configuration file which allows you to: Assign the read counts generated for each sequencing file to the appropriate sample condition Specify which conditions you want to compare in order to generate phenotypes Set several data quality filtering and normalization parameters Specify how to score genes
This script also generates a set of standard graphs using screen_analysis.py
[Optional] Generate graphs interactively using screen_analysis.py
(ScreenProcessing no longer uses Bowtie to align sequencing reads; if you want to use or fork from this functionality use an earlier version of the program)
A PDF slideshow with a step-by-step tutorial of screen analysis using the data files included in the Demo folder can found here: ScreenProcessing Demo
The demo files represent a tiny slice of the full sequencing dataset to speed up the download and demo scripts. The full complement of sequencing data used for the cell growth and cholera toxin sensitivity CRISPRi screens published in Gilbert and Horlbeck et al., Cell 2014 can be accessed here: data link


Corn Syrup in Beer Explained
In an upset that could have earned one a fortune on the prop bet market, corn syrup emerged as Super Bowl LIII’s biggest villain (non-football division). In case you missed it:
My immediate reaction was “Where in the world does a beer brewed with rice get off calling out other beers for using corn?” Then I wondered which of AB InBev’s many fine products also used corn/corn syrup? Based on available information from Ab InBev’s own tapintoyourbeer.com the answer is: A lot of them. Here is just a partial list:
- Bud Ice
- Bud Light Lime
- Bud Light Platinum
- Budweiser Select and Select 55
- Busch, including Light and Ice Varieties
- Natural Light, Natural Ice, and our good friend, Natty Daddy
We can now safely add rank hypocrisy to AB InBev’s many and sundry other crimes.
I was going to save the adjunct topic for a larger glossary page, but because the Dilly Dilly boys delivered corn syrup to a couple of castles on Super Bowl Sunday, let’s just tackle brewing additives now. I am guilty of using the term adjunct to imply poor quality at times, but technically an adjunct is any sugar source other than barley malt used in brewing beer.
By tradition, beer only uses barley malt for the sugar. Anything beyond malt, water, hops and yeast is generally considered an adjunct. For funsies, here are some common adjuncts:
- Rye and Oats
- Fruits and Honey
- Herbs and Spices
- Chocolate and Coffee
- Corn and Rice
Any of the above can be used for good or ill, depending on the brewery. One of my own favorite homebrew recipes uses plain old table sugar. It’s fantastic. A lot of those fancy Double IPAs use just straight sugar to juice up the ABV. One of the best beers I’ve had in the last 5 or so years was an Imperial Rice IPA, which was as delicious and easy-to-drink as it was high in ABV.
Corn syrup, despite Bud Light’s assertion, does not automatically indicate a beer is bad or unhealthy. Corn and rice, in addition to being cheap sources of sugar, tend to impart a lightness in color and taste. Both AB InBev and MillerCoors are looking to make bland, straw-colored beers while keeping production costs as low as possible. Corn and rice both help in the endeavor.
So, should you worry about corn syrup being in your beer? I would argue if you’re worried about what’s in your beer, you may want to remember that the end product is a literal poison and therefore said poison’s sugar source shouldn’t overly concern you.
Bottom line: If you’re drinking a Bud, Miller, or Coors while worrying about your health, you’re doing it wrong. I hope those Dilly Dilly guys ended up getting the Plague.


GVariant Text FormatGVariant Text Format — textual representation of GVariants |
This page attempts to document the GVariant text format as produced by
g_variant_print()
and parsed by the
g_variant_parse()
family of functions. In most
cases the style closely resembles the formatting of literals in Python but there are some additions and
exceptions.
The functions that deal with GVariant text format absolutely always deal in utf-8. Conceptually, GVariant text format is a string of Unicode characters -- not bytes. Non-ASCII but otherwise printable Unicode characters are not treated any differently from normal ASCII characters.
The parser makes two passes. The purpose of the first pass is to determine the type of the value being parsed. The second pass does the actual parsing. Based on the fact that all elements in an array have to have the same type, GVariant is able to make some deductions that would not otherwise be possible. As an example:
1 |
[[1, 2, 3], [4, 5, 6]] |
is parsed as an array of arrays of integers (type 'aai
'), but
1 |
[[1, 2, 3], [4, 5, 6.0]] |
is parsed as a array of arrays of doubles (type 'aad
').
As another example, GVariant is able to determine that
1 |
["hello", nothing] |
is an array of maybe strings (type 'ams
').
What the parser accepts as valid input is dependent on context. The API permits for out-of-band type information to be supplied to the parser (which will change its behaviour). This can be seen in the GSettings and GDBus command line utilities where the type information is available from the schema or the remote introspection information. The additional information can cause parses to succeed when they would not otherwise have been able to (by resolving ambiguous type information) or can cause them to fail (due to conflicting type information). Unless stated otherwise, the examples given in this section assume that no out-of-band type data has been given to the parser.
The following table describes the rough meaning of symbols that may appear inside GVariant text format. Each symbol is described in detail in its own section, including usage examples.
|
Symbol |
Meaning |
|
|
|
|
|
String literal. See Strings below. |
|
numbers |
See Numbers below. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type keywords |
See Type Annotations below. |
|
|
|
|
|
The strings true
and false
are parsed as booleans. This is the only
way to specify a boolean value.
Strings literals must be quoted using ""
or ''
. The two are
completely equivalent (except for the fact that each one is unable to contain itself unescaped).
Strings are Unicode strings with no particular encoding. For example, to specify the character
é
, you just write 'é'
. You could also give the Unicode codepoint of
that character (U+E9) as the escape sequence '\u00e9'
. Since the strings are pure
Unicode, you should not attempt to encode the utf-8 byte sequence corresponding to the string using escapes;
it won't work and you'll end up with the individual characters corresponding to each byte.
Unicode escapes of the form \uxxxx
and \Uxxxxxxxx
are supported, in
hexidecimal. The usual control sequence escapes \a
, \b
,
\f
, \n
, \r
, \t
and
\v
are supported. Additionally, a \
before a newline character causes
the newline to be ignored. Finally, any other character following \
is copied literally
(for example, \"
or \\
) but for forwards compatibility with future
additions you should only use this feature when necessary for escaping backslashes or quotes.
The usual octal and hexidecimal escapes \0nnn
and \xnn
are not
supported here. Those escapes are used to encode byte values and GVariant strings are Unicode.
Single-character strings are not interpreted as bytes. Bytes must be specified by their numerical value.
Numbers are given by default as decimal values. Octal and hex values can be given in the usual way (by
prefixing with 0
or 0x
). Note that GVariant considers bytes to be
unsigned integers and will print them as a two digit hexidecimal number by default.
Floating point numbers can also be given in the usual ways, including scientific and hexidecimal notations.
For lack of additional information, integers will be parsed as int32 values by default. If the number has a point or an 'e' in it, then it will be parsed as a double precision floating point number by default. If type information is available (either explicitly or inferred) then that type will be used instead.
Some examples:
5
parses as the int32 value five.
37.5
parses as a floating point value.
3.75e1
parses the same as the value above.
uint64 7
parses seven as a uint64.
See Type Annotations.
Tuples are formed using the same syntax as Python. Here are some examples:
()
parses as the empty tuple.
(5,)
is a tuple containing a single value.
("hello", 42)
is a pair. Note that values of different types are permitted.
Arrays are formed using the same syntax as Python uses for lists (which is arguably the term that GVariant should have used). Note that, unlike Python lists, GVariant arrays are statically typed. This has two implications.
First, all items in the array must have the same type. Second, the type of the array must be known, even in the case that it is empty. This means that (unless there is some other way to infer it) type information will need to be given explicitly for empty arrays.
The parser is able to infer some types based on the fact that all items in an array must have the same type. See the examples below:
[1]
parses (without additional type information) as a one-item array of signed integers.
[1, 2, 3]
parses (similarly) as a three-item array.
[1, 2, 3.0]
parses as an array of doubles. This is the most simple case of the type
inferencing in action.
[(1, 2), (3, 4.0)]
causes the 2 to also be parsed as a double (but the 1 and 4 are still
integers).
["", nothing]
parses as an array of maybe strings. The presence of
"nothing
" clearly implies that the array elements are nullable.
[[], [""]]
will parse properly because the type of the first (empty) array can be
inferred to be equal to the type of the second array (both are arrays of strings).
[b'hello', []]
looks odd but will parse properly.
See Bytestrings
And some examples of errors:
["hello", 42]
fails to parse due to conflicting types.
[]
will fail to parse without additional type information.
Dictionaries and dictionary entries are both specified using the {}
characters.
The dictionary syntax is more commonly used. This is what the printer elects to use in the normal case of dictionary entries appearing in an array (aka "a dictionary"). The separate syntax for dictionary entries is typically only used for when the entries appear on their own, outside of an array (which is valid but unusual). Of course, you are free to use the dictionary entry syntax within arrays but there is no good reason to do so (and the printer itself will never do so). Note that, as with arrays, the type of empty dictionaries must be established (either explicitly or through inference).
The dictionary syntax is the same as Python's syntax for dictionaries. Some examples:
@a{sv} {}
parses as the empty dictionary of everyone's favourite type.
@a{sv} []
is the same as above (owing to the fact that dictionaries are really arrays).
{1: "one", 2: "two", 3: "three"}
parses as a dictionary mapping integers to strings.
The dictionary entry syntax looks just like a pair (2-tuple) that uses braces instead of parens. The presence of a comma immediately following the key differentiates it from the dictionary syntax (which features a colon after the first key). Some examples:
{1, "one"}
is a free-standing dictionary entry that can be parsed on its own or as part
of another container value.
[{1, "one"}, {2, "two"}, {3, "three"}]
is exactly equivalent to the dictionary example
given above.
Variants are denoted using angle brackets (aka "XML brackets"), <>
. They may not
be omitted.
Using <>
effectively disrupts the type inferencing that occurs between array
elements. This can have positive and negative effects.
[<"hello">, <42>]
will parse whereas ["hello", 42]
would
not.
[<['']>, <[]>]
will fail to parse even though [[''], []]
parses successfully. You would need to specify [<['']>, <@as []>]
.
{"title": <"frobit">, "enabled": <true>, width: <800>}
is an example of
perhaps the most pervasive use of both dictionaries and variants.
The syntax for specifying maybe types is inspired by Haskell.
The null case is specified using the keyword nothing
and the non-null case is explicitly
specified using the keyword just
. GVariant allows just
to be omitted
in every case that it is able to unambiguously determine the intention of the writer. There are two cases
where it must be specified:
when using nested maybes, in order to specify the just nothing
case
to establish the nullability of the type of a value without explicitly specifying its full type
Some examples:
just 'hello'
parses as a non-null nullable string.
@ms 'hello'
is the same (demonstrating how just
can be dropped if the type is already
known).
nothing
will not parse wtihout extra type information.
@ms nothing
parses as a null nullable string.
[just 3, nothing]
is an array of nullable integers
[3, nothing]
is the same as the above (demonstrating another place were
just
can be dropped).
[3, just nothing]
parses as an array of maybe maybe integers (type
'ammi'
).
Type annotations allow additional type information to be given to the parser. Depending on the context, this type information can change the output of the parser, cause an error when parsing would otherwise have succeeded or resolve an error when parsing would have otherwise failed.
Type annotations come in two forms: type codes and type keywords.
Type keywords can be seen as more verbose (and more legible) versions of a common subset of the type codes.
The type keywords boolean
, byte
, int16
,
uint16
, int32
, uint32
, handle
,
int64
, uint64
, double
, string
,
objectpath
and literal signature
are each exactly equivalent to their
corresponding type code.
Type codes are an @
("at" sign) followed by a definite GVariant type string. Some
examples:
uint32 5
causes the number to be parsed unsigned instead of signed (the default).
@u 5
is the same
objectpath "/org/gnome/xyz"
creates an object path instead of a normal string
@au []
specifies the type of the empty array (which would not parse otherwise)
@ms ""
indicates that a string value is meant to have a maybe type
The bytestring syntax is a piece of syntactic sugar meant to complement the bytestring APIs in GVariant. It
constructs arrays of non-nul bytes (type 'ay
') with a nul terminator at the end.
Bytestrings are specified with either b""
or b''
. As with strings,
there is no fundamental difference between the two different types of quotes.
Bytestrings support the full range of escapes that you would expect (ie: those supported by
g_strcompress()
. This includes the normal control
sequence escapes (as mentioned in the section on strings) as well as octal and hexidecimal escapes of the
forms \0nnn
and \xnn
.
b'abc'
is equivalent to [byte 0x97, 0x98, 0x99, 0]
.
When formatting arrays of bytes, the printer will choose to display the array as a bytestring if it contains a nul character at the end and no other nul bytes within. Otherwise, it is formatted as a normal array.
Positional parameters are not a part of the normal GVariant text format, but they are mentioned here because
they can be used with g_variant_new_parsed()
.
A positional parameter is indicated with a %
followed by any valid
GVariant Format String. Variable arguments are collected as
specified by the format string and the resulting value is inserted at the current position.
This feature is best explained by example:
1 2 3 4 5 |
char *t = "xyz"; gboolean en = false; GVariant *value; value = g_variant_new_parsed ("{'title': <%s>, 'enabled': <%b>}", t, en); |
This constructs a dictionary mapping strings to variants (type 'a{sv}
') with two items in
it. The key names are parsed from the string and the values for those keys are taken as variable arguments
parameters.
The arguments are always collected in the order that they appear in the string to be parsed. Format strings
that collect multiple arguments are permitted, so you may require more varargs parameters than the number of
%
signs that appear. You can also give format strings that collect no arguments, but
there's no good reason to do so.