Skip to content

Instantly share code, notes, and snippets.

class APIWrapper:
#snippet...
def poll_api(self, tries, initial_delay, delay, backoff, success_list, apifunction, *args):
time.sleep(initial_delay)
for n in range(tries):
try:
status = self.get_status()
if status not in success_list:
@billychan
billychan / example.js
Created October 1, 2016 17:23 — forked from millermedeiros/example.js
execute multiple shell commands in series on node.js
// USAGE ------
// ============
var shell = require('./shellHelper');
// execute a single shell command
shell.exec('npm test --coverage', function(err){
console.log('executed test');
}});
module.exports = function (grunt) {
// show elapsed time at the end
require('time-grunt')(grunt);
// load all grunt tasks
require('load-grunt-tasks')(grunt);
//MODIFIED: add require for connect-modewrite
var modRewrite = require('connect-modrewrite');
grunt.initConfig({
@billychan
billychan / results.js
Last active August 29, 2015 13:56
custom _.results() function
// Iterates an one level object with functions inside and return invoked values
// This was an unmerged PR by me https://github.com/jashkenas/underscore/pull/1482
// Patch it in a Backbone project when needed.
_.results = function(object, context) {
if (typeof context == "undefined") {
context = object;
};
var copy = {};
_.each(object, function(value, key) {
var v = _.isFunction(value) ? value.call(context) : value;
@billychan
billychan / gist:8894271
Created February 9, 2014 04:28
Parse query string in Javascript
# Raw Javascript functions
window.parseQueryString = ->
query = (window.location.search || '?').substr(1)
map = {}
query.replace(/([^&=]+)=?([^&]*)(?:&+|$)/g, (match, key, value) ->
(map[key] = map[key] || []).push(value)
)
return map
@billychan
billychan / gist:8222471
Last active January 2, 2016 00:19
Rails gem generator pattern
# Simple pattern to generate both migration file and copy
# other files
require 'rails/generators'
require 'rails/generators/migration'
require 'rails/generators/active_record'
class FooGemGenerator < Rails::Generators::Base
include Rails::Generators::Migration
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js"></script>
<script src="http://documentcloud.github.io/underscore/underscore-min.js"></script>
<script src="http://documentcloud.github.io/backbone/backbone-min.js"></script>