This file contains 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
@echo off | |
for /f "usebackq delims=\ tokens=2 skip=1" %%a in (`wmic ComputerSystem Get UserName`) do echo:%%a |
This file contains 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 ones_complement(x): | |
return x ^ ((1 << x.bit_length()) - 1) |
This file contains 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 php | |
<?php | |
$_emit_shutdown_function_registered = false; | |
/** | |
* Emits (using echo()) the return value of a closure function. | |
* Keeps a clean separation between legitimate content and error messages. | |
* | |
* If any type of fatal error or Exception was encountered during evaluation, |
This file contains 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 re | |
primePat = re.compile(r'^1?$|^(11+?)\1+$') | |
# http://primes.utm.edu/lists/small/1000.txt | |
primes = [int(x.strip()) for x in ''' | |
2 3 5 7 11 13 17 19 23 29 | |
31 37 41 43 47 53 59 61 67 71 | |
73 79 83 89 97 101 103 107 109 113 |
This file contains 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 random import random | |
from bisect import bisect | |
def weighted_choice(choices): | |
values, weights = zip(*choices) | |
total = 0 | |
cum_weights = [] | |
for w in weights: | |
total += w | |
cum_weights.append(total) |
This file contains 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
<?php | |
/** | |
* HTML builder | |
* @author Chris Lyon <flushot@gmail.com> | |
* | |
* This functional HTML builder was inspired by JSX and eliminates the need to use the unsightly | |
* and error-prone string concatenation method of building HTML markup. You can now cleanly use | |
* nested functions as children and associative arrays as tag attributes. | |
* |
This file contains 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 dfs_visit_key(tree, key_re, visitor_fn): | |
return dfs_walk(tree, \ | |
lambda k, fk, val: \ | |
visitor_fn(fk, val) \ | |
if re.match(key_re, '.'.join(fk)) \ | |
else val) | |
def dfs_walk(tree, visitor_fn, fullkey=None): | |
fullkey = list(fullkey or []) | |
if isinstance(tree, dict): # subtree |
This file contains 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 abc import ABCMeta, abstractmethod | |
import logging | |
import multiprocessing | |
import threading | |
import time | |
try: | |
import queue | |
except ImportError: | |
import Queue as queue |
This file contains 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
/** | |
* A more sane version of json_decode() | |
* | |
* @param $json | |
* @param $assoc when TRUE, json will be decoded as an associative array instead of an object. | |
* @param $depth max stack depth for recursion. | |
* @throws DomainException when parsing failed. | |
* @return the decoded value as an associative array or object (depending on what $assoc was set to). | |
*/ | |
function json_decode_ex($json, $assoc=true, $depth=512) { |
This file contains 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 re | |
import sys | |
import networkx as nx | |
import lxml.etree as et | |
def walk_path(start_path, match_regex=r'.*', recursive=True): |
OlderNewer