Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / .vimrc
Last active December 31, 2015 04:09
My vim configuration
execute pathogen#infect()
set background:dark
syntax on
filetype plugin indent on
set nowrap
set shiftwidth=4
set ts=4
set expandtab
set encoding=utf-8
@prufrock
prufrock / hellolcd.c
Created December 14, 2013 21:48
This is adapted from Arduino's LiquidCrystel HelloWorld Sketch to work the with sainSmart 1602 LCD Keypad. The pins are different then the LCD this sketch was originally made for as this poster pointed out: http://forum.arduino.cc/index.php?topic=96168.0
/*
LiquidCrystal Library - Hello World
Demonstrates the use a 16x2 LCD display. The LiquidCrystal
library works with all LCD displays that are compatible with the
Hitachi HD44780 driver. There are many of them out there, and you
can usually tell them by the 16-pin interface.
This sketch prints "Hello World!" to the LCD
and shows the time.
@prufrock
prufrock / robossh.sh
Last active August 29, 2015 14:27
Rename this to ssh and put it some place where it will override ssh(but don't delete ssh) and you'll get robo backgrounds in your iterm. A modification of the ImageMagick script at http://kpumuk.info/mac-os-x/how-to-show-ssh-host-name-on-the-iterms-background/
#!/bin/bash
# SSH with host name and IP address in background (only in iTerm.app)
# First, check to see if we have the correct terminal!
if [ "$(tty)" == 'not a tty' ] || [ "$TERM_PROGRAM" != "iTerm.app" ] ; then
/usr/bin/ssh "$@"
exit $?
fi
@prufrock
prufrock / index.php
Last active August 29, 2018 02:51
An HTTP server that prints back your request in PHP. Put this file in a folder, open a terminal in the folder and type: "php -S localhost:979"` and whizz bang pow! You'll have a server you can use to test your requests!
<?php
# Inspired by https://stackoverflow.com/a/49007601
function stdout($arg) {
if (is_object($arg) || is_array($arg) || is_resource($arg)) {
$output = print_r($arg, true);
} else {
$output = (string) $arg;
}
file_put_contents('php://stdout', $output . \PHP_EOL);