Skip to content

Instantly share code, notes, and snippets.

View bartek's full-sized avatar
🐗

Bartek Ciszkowski bartek

🐗
View GitHub Profile
@bartek
bartek / dict_to_xml.py
Created April 17, 2014 19:39
Convert a list of dictionaries into an XML representation
from xml.etree.ElementTree import Element, SubElement
def dict_to_xml(data, root_name='events'):
# a list of dictionaries, converted into xml.
root = Element(root_name)
def _make_xml(i_root, data_dict):
for field, val in data_dict.iteritems():
if isinstance(val, dict):
i_data = SubElement(i_root, field)
function getSomethingMagicalFromRemote() {
var obj = cache.get('obj-key');
if (typeof obj =!="undefined")
return obj
}
// Otherwise init ajax call
$.ajax({ .... })
}
function InvalidFieldException(message) {
this.message = (message || "");
this.name = 'InvalidFieldException';
this.stack = (new Error()).stack;
}
InvalidFieldException.prototype = Error.prototype;
// throw new InvalidFieldException("...")
@bartek
bartek / nose-testrunner.py
Created June 5, 2014 20:35
tests/noserunner.py standard for allowing integration and unittest separation.
import nose
from nose.plugins.base import Plugin
class IntegrationSelector(Plugin):
def options(self, parser, env):
parser.add_option("--exclude-integration",
dest="integration", action="store_false",
default=None)
parser.add_option("--integration",
dest="integration", action="store_true",
$el = $("my-input");
var checkLength = function(input) { if (input.length > 40) { return true } return false; }
var validateEmailAddress = function(input) { return ... }
var rules = [
checkLength,
validateEmailAddress
];
@bartek
bartek / -
Created September 26, 2014 14:21
{"id": "35921", "href": "https://rest.gadventures.com/promotions/35921", "name": "Last Minute 10% off CRPJ141102", "promotion_code": "LM10CRPJ141102", "discount_amount": null, "discount_percent": "10.00", "commission_rate": null, "min_travellers": 0, "sale_start_date": "2014-09-02", "sale_finish_date": "2014-10-02", "product_start_date": null, "product_finish_date": null, "terms_and_conditions": null, "currencies": ["CAD", "CHF", "EUR", "AUD", "USD", "GBP", "NZD", "ZAR"], "room_codes": null, "flags": ["APPLY_AUTOMATICALLY"], "products": [{"id": "506398", "href": "https://rest.gadventures.com/departures/506398", "type": "departures", "sub_type": "Tour"}]}
@bartek
bartek / -
Created October 8, 2014 17:09
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6WH/85Y1ShcZWCq29dLpapwe2q7g3pSScybaJuYGO0gxfCDWEYr8+kadw5GB7vIQJvUcK+XLgurWRtjrVYMIfuWsHW1VG8Aq2GEh3UiWbew8l07xcAQTRhdWboZnYszf+72jkK72do42sp5GblQKp6iFtml6sEgL2BtpJojdkrs8j8wocAmFAgdYKmkcPTGRhxCP7actWd7rNyn0Tc4GW5kQLyzajQoEMLjtzVNniXqIue2/iydoQCCKLGGsWLQ0VQCXzb++30atda4dzdGy0tQBMV4osYcXKNSuroCK29v8vLhtpVrfAY9k3IAxJsyu0Qd7Wr931F5Rqlso0gNKwQ== bartekc@dhcp147.gap.ca
@bartek
bartek / index.js
Created June 9, 2015 14:05
requirebin sketch
// require() some stuff from npm (like you were using browserify)
// and then hit Run Code to run it on the right
var request = require('superagent'),
_ = require('lodash')
function collectResponse(err, resp) {
var results = document.getElementById('results')
_.each(resp.body.results, function(item) {
var child = document.createElement("div")
child.innerHTML = item.product_line + " -- " + item.departures_start_date
@bartek
bartek / index.js
Created June 12, 2015 19:45
requirebin sketch
// require() some stuff from npm (like you were using browserify)
// and then hit Run Code to run it on the right
var request = require('superagent'),
_ = require('lodash')
function collectResponse(err, resp) {
var results = document.getElementById('results')
_.each(resp.body.results, function(item) {
var child = document.createElement("div")
child.innerHTML = item.product_line + " -- " + item.departures_start_date
# section1.1.7 from SICP written in python .. was just making sure I understood how it all worked.
def square(x):
return x * x
def sqrt_iter(guess, x):
if good_enough(guess, x):
return guess
else:
return sqrt_iter(improve(guess, x), x)