Skip to content

Instantly share code, notes, and snippets.

@hawx
hawx / .bashrc
Last active April 26, 2017 15:57
.files
git_author() {
if [ -z "$GIT_AUTHOR_NAME" ]; then
echo "developer"
else
echo "$GIT_AUTHOR_NAME"
fi
}
export PS1='\[\033]0;$MSYSTEM:\w\007\]\n\[\033[32m\]$(git_author) @ \h \[\033[33m\]\w$(__git_ps1) \[\033[0m\]\n$ '
@hawx
hawx / chunkyrequest.cs
Created February 25, 2014 15:02
ChunkyRequest
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using ShiftIt.Http;
namespace Chunkyness
{
public class ChunkyRequest
@hawx
hawx / send.sh
Created March 31, 2014 09:39
send
#!/usr/bin/env sh
#
# Usage: send <username> <password> <accountReference> <recipient> < file
# eg. send [email protected] secretPassword EX00000 44132133113213 < mymessage.txt
body=$(cat)
curl -X POST --user "$1:$2" -d@- "https://api.esendex.com/v1.0/messagedispatcher" <<EOS
<?xml version="1.0" encoding="utf-8"?>
<messages>
@hawx
hawx / dominant.go
Last active August 29, 2015 14:00
Dominant Palette Drawer
// Usage: dominant < in > out
package main
import (
"github.com/hawx/img/utils"
"github.com/hawx/rgoybiv"
"image"
"image/draw"
)
var redis = require('redis').createClient();
var app = require('express')();
var total = 0, count = 0;
redis.on('message', function(channel, message) {
if (channel == "requests") {
var obj = JSON.parse(message);
total += obj.duration;
@hawx
hawx / create-repo
Created August 18, 2014 20:57
Create git repos on a server with post-update hook setup
#!/usr/bin/env sh
REPO=$1
mkdir /opt/git/$REPO.git
git init --bare /opt/git/$REPO.git
cd /opt/git/$REPO.git
mv hooks/post-update.sample hooks/post-update
@hawx
hawx / jsx.js
Last active August 29, 2015 14:06
What JSX should be
// Given we have some,
// function el(name) { return function() { ... } }
var Dropdown = el('Dropdown'),
Menu = el('Menu'),
MenuItem = el('MenuItem');
var dropdown = Dropdown(
'A dropdown list',
Menu(
@hawx
hawx / maths.lisp
Created February 5, 2015 20:00
Old maths homework solving
#!/usr/bin/env newlisp
;; Prints the nth fibonacci number
(define (fib n)
(if (< n 2)
1
(+ (fib (- n 1))
(fib (- n 2)))))
;; Solves equations of the form
@hawx
hawx / proc_injector.rb
Created February 12, 2015 18:25
'set' local variables within a proc before it runs
# @param args [Hash{Symbol=>Object}]
def run_proc_with_locals(args, proc)
k = Class.new
args.each do |sym, v|
k.send(:define_method, sym) { v }
end
k.new.instance_exec(&proc)
end
tha_proc = proc do
@hawx
hawx / runner.rb
Created February 12, 2015 18:26
simple runner for before/after each/all tasks
# Sometimes you want to run a set of blocks before/after
# each/all of something. Problem solved.
#
# @example
#
# class CountDown < Runner
# before :all do |arr|
# arr.collect {|i| i + 1 }
# end
#