This file contains 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 operator, itertools | |
def inspiration(*nums): | |
assert all(isinstance(x, int) and x > 0 for x in nums), "a deck of cards contains only integers" | |
ops = {operator.add: '+', operator.sub: '-', operator.mul: '*', operator.div: '/'} | |
possibilities = {reduce(lambda v, t: t[0](v,t[1]), zip(o, n[1:]), n[0]): (n, o) \ | |
for n in itertools.permutations(nums[:-1]) for o in itertools.product(ops.keys(), repeat=len(nums)-2)} | |
try: | |
result_nums, result_ops = possibilities[nums[-1]] | |
return ' '.join('%s %s' % x for x in zip(result_nums, (ops[o] for o in result_ops))) + ' %s' % str(result_nums[-1]) | |
except KeyError: |
This file contains 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 logging | |
import tornado.web | |
import tornado.ioloop | |
from tornado.options import options, define, parse_command_line | |
define('port', default=8888, type=int, metavar='PORT', help='port to listen on') | |
define('timeout', default=20.0, type=float, metavar='SECONDS', help='number of seconds to timeout calls after') | |
class MainHandler(tornado.web.RequestHandler): |
This file contains 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
<?xml version="1.0"?> | |
<root> | |
<vkchangeinputsourcedef> | |
<name>KeyCode::VK_CHANGE_INPUTSOURCE_HEBREW</name> | |
<languagecode>he</languagecode> | |
<inputsourceid_equal>org.unknown.keylayout.Hebrew</inputsourceid_equal> | |
</vkchangeinputsourcedef> | |
<item> | |
<name>Option+Shift to switch between English and Hebrew</name> |
This file contains 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
// ==UserScript== | |
// @name Event Merge for Google Calendar™ (by @imightbeAmy. Thanks!) | |
// @namespace gcal-multical-event-merge | |
// @include https://www.google.com/calendar/* | |
// @include http://www.google.com/calendar/* | |
// @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js | |
// @version 1 | |
// @grant none | |
// ==/UserScript== |
This file contains 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 operator | |
from sys import maxint | |
from itertools import permutations, product | |
ops = [operator.add, operator.sub, operator.mul, operator.div] | |
possibilities = set(reduce(lambda v, t: t[0](v,t[1]), zip(o, n[1:]), n[0]) for n in permutations(range(1,5)) for o in product(ops, repeat=3)) | |
# Without repeating operators: | |
# possibilities = set(reduce(lambda v, t: t[0](v,t[1]), zip(o, n[1:]), n[0]) for n in permutations(range(1,5)) for o in permutations(ops, repeat=3)) |
This file contains 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 BooleanFunctor: | |
""" | |
A neat trick: this can be used in conditions, where it returns the value of b, | |
or as a decorator, where it returns the decorated function if b, or a lambda returning | |
falseValue otherwise. | |
>>> if BooleanFunctor(cond): | |
... # only if cond is true | |
... pass |
This file contains 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
# -*- coding: utf-8 -*- | |
# <nbformat>3.0</nbformat> | |
# <codecell> | |
from urllib2 import urlopen | |
import json | |
This file contains 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
#!/usr/bin/env ruby | |
OUT_FILE = "#{ENV['HOME']}/Pictures/BingWallpaper.jpg" | |
require 'open-uri' | |
f = open('http://www.bing.com/HPImageArchive.aspx?format=xml&idx=1&n=1&mkt=en-US') | |
s = f.read | |
img_base = s.match('<urlBase>(.*)</urlBase>').captures[0] | |
img_url = 'http://www.bing.com/' + img_base + '_1920x1200.jpg' |
This file contains 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
#!/bin/sh | |
# | |
# Outputs $1 random lines from stdin. | |
# Sample usage: cat src_file | sort -R | head -n 100 | |
sort -R | head -n $1 |
This file contains 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
#!/usr/bin/env ruby | |
# -*- coding: utf-8 -*- | |
TENBIS_ID = 'xxx' # Get this value by inspecting the AJAX request | |
NOTIFY_EXPIRE = '30000' | |
require 'open-uri' | |
require 'json' |