Skip to content

Instantly share code, notes, and snippets.

#!env php
<?php
//script is intended to run from site directory
//tested on Joomla 2.5
$currentDir = getcwd();
echo "Running from \"${currentDir}\"\n";
$configPath = $currentDir.'/configuration.php';
$backupFolderPath = $currentDir.'/.backupdb';
$backupPath = $backupFolderPath.'/backup.sql';
scramble = lambda word: [''.join(x) for c in range(len(word)) for x in itertools.combinations(word,c)]
# example:
# >>> scramble('sample')
# ['', 's', 'a', 'm', 'p', 'l', 'e', 'sa', 'sm', 'sp', 'sl', 'se', 'am', 'ap', 'al', 'ae', 'mp', 'ml', 'me', 'pl', 'pe', 'le', 'sam', 'sap', 'sal', 'sae', 'smp', 'sml', 'sme', 'spl', 'spe', 'sle', 'amp', 'aml', 'ame', 'apl', 'ape', 'ale', 'mpl', 'mpe', 'mle', 'ple', 'samp', 'saml', 'same', 'sapl', 'sape', 'sale', 'smpl', 'smpe', 'smle', 'sple', 'ampl', 'ampe', 'amle', 'aple', 'mple', 'sampl', 'sampe', 'samle', 'saple', 'smple', 'ample']
# inspired by http://sahandsaba.com/thirty-python-language-features-and-tricks-you-may-not-know.html
@d9k
d9k / tree.md
Created June 3, 2016 10:42 — forked from hrldcpr/tree.md
one-line tree in python

One-line Tree in Python

Using Python's built-in defaultdict we can easily define a tree data structure:

def tree(): return defaultdict(tree)

That's it!

@d9k
d9k / hg-log-compact-template-2.sh
Last active April 28, 2016 00:32
hg log templates
hg log -G -l 10 --template "{rev} [{phase}] {date|isodate}, {author|person}, {node}\n {desc}\n\n"
#210 [public] 2016-04-23 02:41 +0300, d9k, 117988d537c4bfc178e44ef562a41944c1bdb942
# one click buy form: payment system field
//see https://github.com/mfunkie/react-overlay
import { Overlay } from 'react-overlay';
// or
const { Overlay } = require('react-overlay');
// or
var Overlay = require('react-overlay').Overlay;
@d9k
d9k / delete-zero-length.sh
Last active November 27, 2015 01:18
vkopt output mp3 shuffle download
#/bin/bash
find tracks -size 0c -delete
# run "bc -l" and then...
define fpow(a, b) { return e(b * l(a)); }
# example (calculate monthly percent by year percent): pow(1.08, 1/12)
# 1.00643403011000345482
function pyv() {
. ./venv/bin/activate
which python
python --version
}
# schema
class LoginSchema(Schema):
login = SchemaNode(
String(),
title='Login',
widget=TextInputWidget(),
)
password = SchemaNode(
@d9k
d9k / recaptcha.py
Last active September 12, 2021 05:55 — forked from reedobrien/recaptcha.py
Deform Recaptcha Widget
## original is on https://gist.github.com/reedobrien/701444
## it's newer version (works on python 3)
## code may contain bugs, check carefully
import deform
import deform.widget
from deform.widget import CheckedInputWidget
from colander import null, Invalid
from pyramid.threadlocal import get_current_request