This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Global Data example | |
function load_problem(tokens) { | |
global_data = get_global_data(tokens) | |
return global_data.num_cases, function(tokens) { | |
case_specific_data = get_case_data(tokens) | |
return function() { | |
// Do a bunch of math with global_data and case_specific_data | |
return solution | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def emit(list_of_elements): | |
for elem in list_of_elements: | |
if elem.thing1 > 0: | |
yield elem.thing1 | |
if elem.thing2 < 0: | |
yield elem.thing2 | |
if elem.thing3 != 0: | |
yield elem.thing3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SyncClientThread: | |
def __init__(self): | |
... | |
self.stop = False | |
self.nostop_depth = 0 | |
def Stop(self): | |
self.stop = True | |
def IsStopped(self): | |
return self.nostop_depth == 0 and self.stop |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Try appending ?ts=2 to the url of this page. | |
# Then try ?ts=4 | |
# Then ?ts=8 | |
def my_member_function(self, argument): | |
for value in range(10): | |
# Notice how, as the indents shift, all the arguments | |
# to this function stay vertically aligned. | |
self.my_other_func(argument, | |
value, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create a promise that is resolved after `timeout` ms | |
const promiseTimer = timeout => new Promise(resolve => setTimeout(() => resolve(null), timeout)) | |
async function counter(max) { | |
for(let i = 0; i < max; i++) { | |
console.log("Counting:", i) | |
// This is the important part. "await" allows the function to appear to block; | |
// other asynchronous work can be done here. This is basically the equivelent | |
// of a .then on promiseTimer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_rows(selected_table): | |
for row in selected_table.css('tr'): | |
cells = row.css('td').extract() | |
yield tuple(cells) | |
def find_bge_table(response): | |
for table_element in response.css('table'): | |
table = list(get_rows(table_element)) | |
if any(row[0] == "BGE" for row in table): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import itertools | |
import functools | |
def keyed_product(**iterables): | |
''' | |
Same as itertools.product, but returns key-value dicts. Basically, given | |
a dict of key => list, return every possible combination of all the | |
values in the lists, and their associated keys. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import itertools | |
import functools | |
def keyed_product(**iterables): | |
''' | |
Same as itertools.product, but returns key-value dicts. Basically, given | |
a dict of key => list, return every possible combination of all the | |
values in the lists, and their associated keys. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import itertools | |
import functools | |
def keyed_product(**iterables): | |
''' | |
Same as itertools.product, but returns key-value dicts. Basically, given | |
a dict of key => list, return every possible combination of all the | |
values in the lists, and their associated keys. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <stdarg.h> | |
/** | |
* Write a message to stderr, followed by a newline, then exit the program. | |
* This helper function is provided because C doesn't have throwable exceptions | |
* or any similarly ergonomic error handling. | |
* | |
* Arguments to this function are similar to `fprintf`; see online documentation |