Skip to content

Instantly share code, notes, and snippets.

View ernstwi's full-sized avatar

Ernst Widerberg ernstwi

View GitHub Profile
@bgadrian
bgadrian / set.go
Last active April 23, 2024 13:50
How to implement a simple set data structure in golang
type Set struct {
list map[int]struct{} //empty structs occupy 0 memory
}
func (s *Set) Has(v int) bool {
_, ok := s.list[v]
return ok
}
@sbz
sbz / tty-size.c
Created April 14, 2017 02:05
get terminal size using ioctl get win size (TIOCGWINSZ) in C
#include <sys/ioctl.h>
#include <stdio.h>
#include <unistd.h>
int
main(void) {
struct winsize ws;
ioctl(STDIN_FILENO, TIOCGWINSZ, &ws);
printf ("lines %d\n", ws.ws_row);
@arteymix
arteymix / git-archive-all
Last active March 15, 2024 10:55
Archive HEAD and its submodules recursively
#!/usr/bin/env sh
if [ -z $1 ]; then
echo "You must specify a super-archive name."
exit 1
fi
git archive --prefix "$1/" -o "$1.tar" HEAD
git submodule foreach --recursive "git archive --prefix=$1/\$path/ --output=\$sha1.tar HEAD && tar --concatenate --file=$(pwd)/$1.tar \$sha1.tar && rm \$sha1.tar"
@MicahElliott
MicahElliott / colortrans.py
Created November 29, 2010 07:57
Convert values between RGB hex codes and xterm-256 color codes.
#! /usr/bin/env python
""" Convert values between RGB hex codes and xterm-256 color codes.
Nice long listing of all 256 colors and their codes. Useful for
developing console color themes, or even script output schemes.
Resources:
* http://en.wikipedia.org/wiki/8-bit_color
* http://en.wikipedia.org/wiki/ANSI_escape_code