Skip to content

Instantly share code, notes, and snippets.

@nb
nb / gist:677b416912e14ec44b16
Created September 18, 2014 13:22
Keybase Verification
### Keybase proof
I hereby claim:
* I am nb on github.
* I am nikolayb (https://keybase.io/nikolayb) on keybase.
* I have a public key whose fingerprint is 5B90 5510 BE15 69CB 2D45 146F 9452 16AC 9610 D078
To claim this, I am signing this object:
it( 'should handle series of same component', function() {
var expectedResultString = '<span><a href="#">baba</a><a href="#">dyado</a></span>',
translatedComponent = translate( '{{link}}baba{{/link}}{{link}}dyado{{/link}}', { components: { link: link } } );
assert.equal( expectedResultString, stripReactAttributes( React.renderToString( translatedComponent ) ) );
} );
it( 'should handle wrong cross-nesting', function() {
var expectedResultString = '', // how do we return error?
translatedComponent = translate( '{{link}}a{{em}}b{{/link}}c{{/em}}', { components: { link: link, em: em } } );
assert.equal( expectedResultString, stripReactAttributes( React.renderToString( translatedComponent ) ) );
@nb
nb / gist:e6698066e0b0d686a026
Created February 20, 2015 22:53
ssh into a container for debugging
# look for the ID of the `default` VM
vagrant global-status
vagrant ssh <default-id>
# install nsenter
docker run -v /usr/local/bin:/target jpetazzo/nsenter
# get the container id, not the image id
docker ps
import unittest
def is_interval(interval, **kwargs):
to_list = lambda value: [value] if isinstance(value, basestring) else value
list_from_kwarg = lambda key: to_list(kwargs.get(key, []))
units = ['y', 'm', 'd', 'h', 'i', 's']
only = list_from_kwarg('only')
if only:
return is_interval(interval, with_ = only, without = list(set(units) - set(only)))
with_ = list_from_kwarg('with_')
@nb
nb / copy-playlist-files.py
Created April 17, 2009 16:39
Copy files from an iTunes playlist to a directory
#!/usr/bin/env python
import sys, shutil, os.path
if len(sys.argv) != 3:
sys.stderr.write('Usage: %s PLAYLIST DEST\n\n' % sys.argv[0])
sys.exit(1)
exported, dest = sys.argv[1:]
lines = unicode(open(exported).read(), 'utf16').split('\r')[1:]
files = ['/Volumes/' + line.split('\t')[-1].replace(':', '/') for line in lines]
for file in files:
if os.path.exists(file) and os.path.isfile(file): shutil.copy(file, dest)
@nb
nb / baba-htaccess
Created March 30, 2010 12:39
Using more than one WordPress codebase for multiple installs without symlinks
RewriteEngine On
RewriteBase /baba/
RewriteRule ^$ ../trunk/$1?_config=baba [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ../trunk/$1?_config=baba [L,QSA]
<?php
require_once 'PHPUnit/Framework.php';
/**
* Matches a php code string upon a template of tokens
*
* @param string $code String of php code.
* @param string $template See the tests below for examples.
*
* @return array|false Associative array of all variables or false if no match was found
"""
E=7
TALLET +
SIGNAL
------
ELAINE
"""
letters = set('T A L L E T S I G N A L E L A I N E'.split())
assoc = {letter: None for letter in letters}
# coding: utf-8
import email, imaplib, chardet, pickle
m = imaplib.IMAP4_SSL('imap.gmail.com', 993)
m.login('nb@nikolay.bg', 'тринайсетзелениголиорангутанагонятгоркатапеперудка')
m.select('&BD8ENQRCBDA- &BDcEMAQ0BDAERwQw-') # пета задача
typ, data = m.search(None, 'ALL')
essays = []
for num in data[0].split():
print 'Getting %s' % num
# coding: utf-8
from xmlrpclib import ServerProxy, Binary
import pickle
import re
server = ServerProxy("http://path-to-not-so-random-wp-installtion/xmlrpc.php")
essays = pickle.load(open('essays'))
for essay in essays:
try:
match = re.search(r'<([^<>]+)>\s*$', essay['from'])