Skip to content

Instantly share code, notes, and snippets.

View pestilence669's full-sized avatar

Paul Chandler pestilence669

View GitHub Profile
@pestilence669
pestilence669 / macClipboardCopier.py
Last active August 29, 2015 14:03
Copies a string into the clipboard... on a Mac.
#!/usr/bin/env python
# vim: set ts=4 sw=4 noet:
import argparse
def shoveIntoClipboard(contents):
"Copies a string into the clipboard... on a Mac"
p = subprocess.Popen(['pbcopy'], stdin = subprocess.PIPE)
p.stdin.write(contents)
p.stdin.close()
return p.wait() == 0
@pestilence669
pestilence669 / facebull.aco.py
Last active January 11, 2016 23:11
Small experiment with Ant Colony Optimization for solving Facebook's FaceBull puzzle. This solution was not a winner; nor were my genetic algorithm, branch & bound, simulated annealing or brute force approaches.
#!/usr/bin/env python
# vim: set ts=4 sw=4 noet:
################################################################################
# Author: Paul Chandler <[email protected]>
# Facebook's FaceBull Puzzle
#
# NOTE: If psyco is installed, it's imported & enabled. The improvement is
# unimpressive, but it's something.
#
# /me crosses fingers
@pestilence669
pestilence669 / unfck_gpc.php
Last active August 29, 2015 14:03
Old code I posted in the comments of php.net years ago. It's boilerplate code for automating the handling of PHP's "magic" quoting behavior. It was copy and pasted frequently, after I renamed it "unfck_gpc" instead of "unfuck_gpc," which was deleted as offensive. As far as I can tell, the only big project that still uses it, is a Russian CMS.
<?php
// vim: set ts=4 sw=4 noet:
/*
In the example above, the author forgets to include $_REQUEST,
which is also slashed (using PHP 4.3.8).
It's good practice to include a routine to "unslash" or "slash"
variables, if something happens that isn't to your expectation.
However your PHP is written to depend on this option, it becomes
important to support either when or if others deploy your code.