Skip to content

Instantly share code, notes, and snippets.

@halferty
halferty / strace.sh
Created March 24, 2015 20:17
Strace for stg APIs
# Watch incoming connections with a given string
strace -f -e trace=network -s 100000 -p <pid> 2>&1 | grep --line-buffered <string> -a4 -b4
@halferty
halferty / monkey_patching.rb
Last active August 29, 2015 14:17
Monkey patching
class Object
def if?(method_symbol=nil, &block)
if method_symbol.is_a?(Symbol)
(self.send(method_symbol))? self : nil
else
(yield(self))? self : nil
end
end
def unless?(method_symbol=nil, &block)
@halferty
halferty / recursively_expand_erb_files
Created March 25, 2015 06:47
Recursively expand ERB files
#!/usr/bin/env ruby
require 'erb'
Dir.glob("**/*.erb").each do |erb_file|
File.write(erb_file.sub(/\.erb/, ''), ERB.new(File.read(erb_file)).result)
end
@halferty
halferty / untitled.sh
Created March 25, 2015 21:23
Don't be a sucker and use JVM 1.8 on OS X
alias with-sensible-jvm='JAVA_HOME="`/usr/libexec/java_home -v '1.6*'`" $@'
@halferty
halferty / main.c
Created March 28, 2015 17:02
Truly minimal OpenGL example
#include "stdafx.h"
#include <GL/gl.h>
#include <GL/glu.h>
#define MAX_LOADSTRING 100
HINSTANCE hInstance;
HWND hWnd;
LONG WINAPI WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
static PAINTSTRUCT ps;
switch (uMsg) {
@halferty
halferty / main.c
Created March 29, 2015 08:03
OpenGL win32 multi-window example
#include "stdafx.h"
#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#define MAX_LOADSTRING 100
HINSTANCE hInstance;
HWND hWnd, hWnd2;
struct WindowData {
HWND window;
@halferty
halferty / ledripple.ino
Created May 4, 2015 22:01
Radioshack RGB LED strip Ripple color change test with IR remote control
#include <avr/pgmspace.h>
#include <IRremote.h>
#include <IRremoteInt.h>
#define DATA_1 (PORTC |= 0X01)
#define DATA_0 (PORTC &= 0XFE)
#define STRIP_PINOUT (DDRC=0xFF)
#define NOP __asm__("nop\n\t");
#define NOP28 NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP
#define NOP9 NOP NOP NOP NOP NOP NOP NOP NOP NOP
@halferty
halferty / killify.sh
Created May 27, 2015 21:29
The development world is full of badly-behaved processes that stop responding to ctrl-c (WEBrick & jetty, I'm lookin' at you!). Make them stop with a good old fashioned kill -9.
function killify() {
if [ $# -ne 0 ]; then
kill -9 `ps auxww | grep "$@" | grep -v grep | tr -s ' ' | cut -d' ' -f 2`
fi
}
~ »wc -l test.txt
23759 test.txt
~ »function truncate() { echo "`tail -n100 $1`" > $1; }; truncate test.txt
~ »wc -l test.txt
100 test.txt
~ »
@halferty
halferty / 001
Last active August 29, 2015 14:23
c code wrapped in bash script for quickly testing stuff.
#!/bin/bash
rm -f tempfifo1
rm -f a.out
mkfifo tempfifo1 2>/dev/null
cat << EOF > tempfifo1 &
#include <stdio.h>
int main(int argc, char ** argv) {
printf("Hello, world!\n");
return 0;