Skip to content

Instantly share code, notes, and snippets.

@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'])
#!/usr/bin/env python
import os
import sys
import time
import random
messages = {
0: "It is Midnight! And that's all",
1: "It's 1 o'clock and the weather outside is fine. Do you wanna go out for a walk?",
6: "A third of the number of the beast o'clock",
}
<?php
/*
Plugin Name: Different theme
Description: Use a different theme on certain conditions
Author: Nikolay Bachiyski
Version: 1.0
*/
class Different_Theme {
function __construct() {
@nb
nb / periodic-table.json
Created September 8, 2010 18:06
Structured information about all the elements in the periodic table
[[1, "Hydrogen", "H"], [2, "Helium", "He"], [3, "Lithium", "Li"], [4, "Beryllium", "Be"], [5, "Boron", "B"], [6, "Carbon", "C"], [7, "Nitrogen", "N"], [8, "Oxygen", "O"], [9, "Fluorine", "F"], [10, "Neon", "Ne"], [11, "Sodium", "Na"], [12, "Magnesium", "Mg"], [13, "Aluminium", "Al"], [14, "Silicon", "Si"], [15, "Phosphorus", "P"], [16, "Sulfur", "S"], [17, "Chlorine", "Cl"], [18, "Argon", "Ar"], [19, "Potassium", "K"], [20, "Calcium", "Ca"], [21, "Scandium", "Sc"], [22, "Titanium", "Ti"], [23, "Vanadium", "V"], [24, "Chromium", "Cr"], [25, "Manganese", "Mn"], [26, "Iron", "Fe"], [27, "Cobalt", "Co"], [28, "Nickel", "Ni"], [29, "Copper", "Cu"], [30, "Zinc", "Zn"], [31, "Gallium", "Ga"], [32, "Germanium", "Ge"], [33, "Arsenic", "As"], [34, "Selenium", "Se"], [35, "Bromine", "Br"], [36, "Krypton", "Kr"], [37, "Rubidium", "Rb"], [38, "Strontium", "Sr"], [39, "Yttrium", "Y"], [40, "Zirconium", "Zr"], [41, "Niobium", "Nb"], [42, "Molybdenum", "Mo"], [43, "Technetium", "Tc"], [44, "Ruthenium", "Ru"], [45, "Rhodium",
<?php
function redirect_on_bad_login( $redirect_to, $redirect_to_from_request, $user ) {
if ( is_wp_error( $user ) && isset( $_POST['wp-submit'] ) ) {
wp_redirect( 'http://dir.bg/' );
exit();
}
return $redirect_to;
}