Skip to content

Instantly share code, notes, and snippets.

View mrnugget's full-sized avatar

Thorsten Ball mrnugget

View GitHub Profile
@mrnugget
mrnugget / intncpy.c
Created September 8, 2014 15:36
Copies the binary representation of an integer to a string
#include <string.h>
#include <stdio.h>
#define INT_BITS_NUM (8 * sizeof(int))
void intncpy(int src, char *dest, int len)
{
int bit = INT_BITS_NUM - 1;
int pos, is_set;
@mrnugget
mrnugget / simple.c
Created August 15, 2014 12:37
Stack Usage
int main(int argc, char *argv[])
{
int i = 10;
int j = 15;
int k = 20;
int l = i + j;
return 0;
}
@mrnugget
mrnugget / Gemfile
Created July 9, 2014 08:23
sidetiq problems
source 'https://rubygems.org'
gem 'sidekiq', '~> 3'
gem 'sidetiq', '~> 0.6.1'
@mrnugget
mrnugget / time_after.go
Created June 5, 2014 16:24
golang time.After
package main
import (
"time"
)
func main() {
ticker := time.Tick(100 * time.Millisecond)
for {
select {
@mrnugget
mrnugget / http_timeout.go
Last active August 29, 2015 14:02
Go snippet: make http requests concurrently but timeout after a specified interval
package main
import "log"
import "net/http"
import "time"
type Response struct {
StatusCode int
Url string
}
@mrnugget
mrnugget / postgis.txt
Created May 20, 2014 07:51
postgis error with json-c
% brew install postgis
==> Downloading http://download.osgeo.org/postgis/source/postgis-2.1.2.tar.gz
Already downloaded: /Library/Caches/Homebrew/postgis-2.1.2.tar.gz
==> ./autogen.sh
;==> ./configure --with-projdir=/usr/local --with-jsondir=/usr/local/opt/json-c --with-pgconfig=/usr/local/Cellar/postgresql/9.3.4/bin/pg_config --disable-nls
checking proj_api.h usability... yes
checking proj_api.h presence... yes
checking for proj_api.h... yes
checking for pj_get_release in -lproj... yes
configure: error: Cannot find json dev files in "/usr/local/opt/json-c"
@mrnugget
mrnugget / progbar.go
Created April 19, 2014 06:12
Simple command line progress bar in Go
package main
import (
"flag"
"fmt"
"io"
"log"
"net/http"
"net/url"
"os"
@mrnugget
mrnugget / test_stty.go
Last active August 29, 2015 14:00
Changing and resetting stty settings
package main
import (
"bytes"
"fmt"
"log"
"os/exec"
"os"
"strings"
)
@mrnugget
mrnugget / read_one_byte.go
Created March 16, 2014 12:54
Use `stty` to change the operation mode of the terminal to disable line-buffering and non-echoing of typed characters. This lets us read one byte from STDIN. This version is currently tested with OS X
package main
import (
"bytes"
"fmt"
"log"
"os"
"os/exec"
)
@mrnugget
mrnugget / c_test_macros.c
Created January 10, 2014 20:07
Simple C test macros based on the LCTHW macros by Zed Shaw (thanks!) with added colors and line number support.
#include <stdio.h>
#define RED "\x1B[31m"
#define GREEN "\x1B[32m"
#define NORMAL "\x1B[0m"
#define STR(s) #s
#define TESTLINE(line) " ("__FILE__ ":" STR(line) ")"
#define test_assert(A, B) if(!(A)) { return B TESTLINE(__LINE__); };