Skip to content

Instantly share code, notes, and snippets.

@dvdbng
dvdbng / enigma.py
Created July 20, 2015 16:25
Number of possible Enigma machine combinations
# Number of possible starting configurations of an enigma machine
letters = 26
rotors_total = 5
rotors_machine = 3
cables = 10 # Must be < letters/2
def f(n): # Factorial
s = 1;
for i in xrange(2, n+1):
s *= i
@dvdbng
dvdbng / gist:4db30f4e3f4c9ad69d5b
Created June 15, 2015 05:25
Find regexp of valid attribute names
var valid_first = [];
var valid_second = [];
for (var i = 0, len = 0xFFFF; i < len; i++) {
try{
var char = String.fromCharCode(i);
if(char.toLowerCase() != char.toUpperCase() && valid_second.indexOf(char.toLowerCase().charCodeAt(0)) >= 0){
continue;
}
document.body.setAttribute('a' + char, '');
document.body.removeAttribute('a' + char);
function getAllProperties(obj){
var allProps = Object.getOwnPropertyNames(obj);
Object.getOwnPropertyNames(Object.getPrototypeOf(obj)).forEach(function add(prop){
if (allProps.indexOf(prop) === -1)
allProps.push(prop)
});
return allProps
}
function jsrecursivegrep(obj, value, length){
@dvdbng
dvdbng / gist:1762527
Created February 7, 2012 22:18
HTML DOM to Markdown in javascript
/*
You can use this to convert a DOM element or a HTML string to markdown.
Usage examples:
var markdown = toMarkdown(document.getElementById("content"));
// With jQuery you can easily convert HTML strings
var markdown = toMarkdown($("<ul><li>Hi!</li></ul>")[0]);
@dvdbng
dvdbng / pruneTree.py
Created February 6, 2012 19:30
Prune DOM tree keeping structure and nodes for wich a function is true
import xml.etree.cElementTree as etree
def traverseEtree(tree,traverser):
traverser.start(tree)
traverser.data(tree.text)
for child in tree:
traverseEtree(child,traverser)
traverser.end(tree)
traverser.data(tree.tail)