Skip to content

Instantly share code, notes, and snippets.

@prufrock
prufrock / linkedlist.c
Last active December 30, 2015 15:08
keeps warning me "initialization from incompatible pointer type [enabled by default]"
#include "linkedlist.h"
int_node linked_list(int data, int_node *link)
{
int_node l = {data, link};
return l;
}
@prufrock
prufrock / binapp.html
Last active December 26, 2015 11:29
Made an example to show how to bind views to dom events.
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<script src="http://documentcloud.github.io/underscore/underscore-min.js"></script>
<script src="http://documentcloud.github.io/backbone/backbone-min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
@prufrock
prufrock / oneLineArray.pl
Last active December 16, 2015 22:39
A simple function to print out the contents a perl array on a single line.
sub oneLineArray
{
my $a = shift @_;
my @array = @$a;
print "(";
foreach(@array){
print " " . $_;
if($_ ne $array[$#array]){
print ",";
}
@prufrock
prufrock / listcomprehension.php
Created May 2, 2013 03:34
Using some of php's built in array functions to do something a little similar to erlang's list comprehensions.
<?php
$a = array(1, 2, 3, 4, 5);
$f = function($a) { return (($a * 2));};
$b = array_values(array_map($f, array_filter($a, function($a) {return ($a > 2);})));
var_dump($b);
@prufrock
prufrock / useless.erl
Last active December 16, 2015 20:39
Playing around with erlang.
%% -*- coding: utf-8 -*-
-module(useless).
-export([useless/0, return_a_number/0, do_the_things_you_do/0]).
useless() ->
"I'm useless!÷".
return_a_number() ->
X = 4 + 4,
Y = X + 7,
@prufrock
prufrock / encode.pl
Created May 31, 2012 03:25
playing around with character encoding in perl
#!/usr/bin/perl
use utf8;
use Encode;
binmode STDOUT, ":encoding(UTF-8)";
$string = "カタカナ, 片仮名";
print "Internal Format: " . $string . "\n";
$octets = encode("utf8", $string);
print "Encoded as UTF-8: " . $octets . "\n";
print "Encoded as UTF-8(Unpacked as Hex): " . unpack("H*",$octets) . "\n";
@prufrock
prufrock / removeSingularKeys.php
Created May 22, 2012 21:46
Makes XML and JSON play nice when being rendered from the same associate array.
<?php
function removeSingularKeys($array, $parent="")
{
$result = array();
$result = $array;
foreach($array as $key => $value){
if(keyIsTheSingularFormOf($key, $parent)){
return $value;
}
if(is_array($value)){
@prufrock
prufrock / .htaccess
Created May 8, 2012 02:34
.htaccess file for cross-origin resource sharing
Header set Access-Control-Allow-Origin *
Header set Access-Control-Allow-Headers "X-Requested-With, Content-Type"
Header set Access-Control-Allow-Methods "PUT, POST, GET, OPTIONS, DELETE"
@prufrock
prufrock / installphpamqp.sh
Created May 5, 2012 00:24
install the php amqp install
cd /tmp/
hg clone http://hg.rabbitmq.com/rabbitmq-c/ rabbitmq-c
cd rabbitmq-c
hg clone http://hg.rabbitmq.com/rabbitmq-codegen codegen
autoreconf -i && ./configure && make && sudo make install
cd /tmp/
lynx http://pecl.php.net/package/amqp #Download latest
tar -xvf amqp-1.0.1.tgz
cd amqp-1.0.1
phpize && ./configure --with-amqp && make && sudo make install
@prufrock
prufrock / betweenQuery.php
Created April 7, 2012 21:57
Performing a between query on an Amazon DynamoDB database.
<?php
//much of this borrowed from the amazon documentation
//http://docs.amazonwebservices.com/amazondynamodb/latest/developerguide/LowLevelPHPTableOperationsExample.html
require_once('include.php');
$response = $dynamoDB->query(array(
'TableName' => $properties["table"]["TableName"]
, 'HashKeyValue' => array(
$properties["table"]["KeySchema"]["HashKeyElement"]["AttributeType"]
=> $hashKey )