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 diff(old, new): | |
""" | |
diff(a, b) = b - a | |
a + diff(a, b) == b | |
""" | |
return strip_dict(map_dicts(diff_atom, old, new)) | |
def diff_atom(old, new): | |
return None if old == new else (old, new) |
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
from itertools import groupby | |
inc = lambda x: x + 1 | |
dec = lambda x: x - 1 | |
def partition_by(f, coll): | |
for _, group in groupby(coll, key=f): | |
yield list(group) | |
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
module.exports = function (ip) { | |
ip = ip || '127.0.0.1'; | |
// Function to test whether or not the request is coming through the trusted reverse proxy. | |
var trust = function (req) { | |
return req.connection.remoteAddress === ip; | |
}; | |
// Function to fetch the remote address from the browser that connected to the reverse proxy. | |
var remoteAddress = function (req) { |
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 checks(namespace): | |
immutable = lambda old_value, new_value: old_value == new_value | |
def gte(other): | |
if callable(other): | |
return lambda value: value >= other() | |
else: | |
return lambda value: value >= other | |
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
#!/usr/bin/env python | |
import os | |
import sys | |
import commands | |
program_name = sys.argv[1] # the program to be focused | |
# get all windows which contain "program_name" from wmcontrol | |
candidates = sorted([x.strip() for x in commands.getoutput(""" wmctrl -l -x | awk -v win="%s" 'tolower($0) ~ win {print $1;}' """ % (program_name, )).split("\n") if x !='']) |
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
var q = query.replace(/\s+/, ' '), | |
re = new RegExp('^(.*?)' + q.split('').join('(.*?)')); | |
function score(junk) { | |
if (!junk) return Infinity; | |
return junk.slice(1).reduce(function (len, item) {return len + item.length}, 0); | |
} | |
return list.reduce(function (best, item) { | |
var junk = item.title.match(re), |
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
suor$ npm install node-gd | |
npm http GET https://registry.npmjs.org/node-gd | |
npm http 304 https://registry.npmjs.org/node-gd | |
> [email protected] install /home/suor/projects/mediavault/node_modules/node-gd | |
> node-waf configure build | |
Checking for program g++ or c++ : /usr/bin/g++ | |
Checking for program cpp : /usr/bin/cpp | |
Checking for program ar : /usr/bin/ar |
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
#!/usr/bin/perl | |
s~^.*//~/~ for @ARGV; | |
system "kdiff3", @ARGV; | |
# kdiff3 %o %m %n -o %t |
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
# Это оригинальный код, всё веселье ниже и по пунктам | |
limit = 5 | |
def intify(array): | |
latest = [] | |
for i in array: | |
row = [] | |
for j in i: | |
row.append(int(j)) |
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
errors = {} | |
for key, value in bundle.data.items(): | |
if not some_test(value): | |
if key not in errors: | |
errors[key] = [] | |
errors[key].append('required.') | |
# R1: использовать defaultdict | |
from collections import defaultdict |