Skip to content

Instantly share code, notes, and snippets.

View pifantastic's full-sized avatar

Aaron Forsander pifantastic

  • Stripe
  • Austin, TX
View GitHub Profile
<?php
$result = function_that_does_crazy_stuff($arg1, $arg2);
// becomes
$result = memoize('function_that_does_crazy_stuff', $arg1, $arg2);
$result = StaticClass::method($arg1, $arg2);
// becomes
$result = memoize(array('StaticClass', 'method'), $arg1, $arg2);
<?php
/**
* Call a function but memoize the results.
*
* @param $callback
* The function to call.
* @param $arguments
* The arguments to pass to callback
*/
<?php
if (isset($_REQUEST['channel']) and $_REQUEST['channel'] >= 0 and $_REQUEST['channel'] < 32 and isset($_REQUEST['state'])) {
$states = file_get_contents('states');
$states[$_REQUEST['channel']] = $_REQUEST['state'] == "on" ? 1 : 0;
$f = fopen('states', 'w');
fwrite($f, $states);
fclose($f);
}
using System;
using System.Runtime.InteropServices;
namespace ConsoleApplication
{
class Program
{
[DllImport("inpout32", EntryPoint = "Out32")]
private static extern void Output(ushort port, short data);
import os, urllib2
print("Listening...")
while True:
os.system("lightthatshitup.exe %s" % urllib2.urlopen("http://fuckwithmysleep.com/states").read())
// FROM
_load: function(obj) {
if (obj) {
for (var prop in obj) {
if (obj.hasOwnProperty(prop) {
this[prop] = obj[prop];
}
}
}
$(function() {
seltzer.init({
database: "/Users/aaron/Downloads/inventories.sqlite"
});
var items = seltzer.sQuery("select * from itemLog");
for (var x = 0; x < items.length; x++) {
air.Introspector.Console.log(items[x]);
}
Drupal.behaviors.myBehavior = function() {
// Retrieve a node synchronously
var node = Drupal.jsonify.load('node', 1);
console.log(node);
// Retrieve a node asynchronously
var node = Drupal.jsonify.load('node', 1, function(node) {
console.log(node);
});
function create_dmg(opts) {
var file, args, info, process;
var options = $.extend({
"source": air.File.applicationStorageDirectory.resolvePath("tmp"),
"output": air.File.applicationStorageDirectory,
"name": "backup-" + (+(new Date())) + ".dmg",
"password": false,
"title": "Backup",
"error": function(e) { log(e); },
<?php
function forum_block($op = 'list', $delta = 0, $edit = array()) {
switch ($op) {
case 'list':
$blocks[0]['info'] = t('Active forum topics');
$blocks[1]['info'] = t('New forum topics');
return $blocks;
case 'configure':