Skip to content

Instantly share code, notes, and snippets.

@ph1ee
ph1ee / parse-csv.c
Last active December 14, 2016 10:35
simple csv parser
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdbool.h>
static char *normalize(char *field) {
assert(field);
typedef enum {
@ph1ee
ph1ee / Makefile
Last active March 18, 2021 09:58
upfind: search for files upward from current working directory
.PHONY: indent
indent:
black upfind
@ph1ee
ph1ee / iper4.py
Last active March 23, 2020 14:33
Import Perforce changelists into Git p4 branch
#!/usr/bin/python
# For initial import, you may want to sync p4 server to an initial changelist
# manually before running this script:
#
# p4 sync -k "...@<initial_changelist>"
# git init
# git commit -m "Initial commit" --allow-empty
# git checkout -b p4
@ph1ee
ph1ee / test-null-stdout.c
Last active September 10, 2016 02:51
Check if stdout is redirected to /dev/null
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <limits.h>
#include <stdlib.h>
int is_stdout_null() {
char path[PATH_MAX], link[PATH_MAX];
sprintf(path, "/proc/self/fd/%d", STDOUT_FILENO);
@ph1ee
ph1ee / check-disk-free-space.sh
Last active August 30, 2016 03:46
Check disk free space
for p in $(df --output=pcent /dev/sda1 /dev/sdb1)
do
[[ ${p/\%*} -gt 90 ]] && df -x tmpfs -x devtmpfs | mail -s "Check disk free space" f@mo.us && return
done
@ph1ee
ph1ee / websave.py
Created July 20, 2016 09:37
Transferring files by HTTP POST with Bottle
#!/usr/bin/env python
import os
from tempfile import gettempdir
from bottle import route, request, run, abort
@route('/')
def root():
return '''
<form action="/upload" method="post" enctype="multipart/form-data">
@ph1ee
ph1ee / gitize.sh
Last active December 21, 2018 02:56
fast git repo setup to altair release artifacts
#!/bin/bash
import() {
git commit -m "Import \"$*\""
}
ls=$(ls)
dirname=$(basename "$(pwd)")
@ph1ee
ph1ee / teamcity-vagrant.buildlog
Created July 8, 2016 07:06
teamcity-vagrant buildlog
sam@x260:~/Workspaces$ git clone https://github.com/rodm/teamcity-vagrant.git
Cloning into 'teamcity-vagrant'...
remote: Counting objects: 130, done.
remote: Total 130 (delta 0), reused 0 (delta 0), pack-reused 130
Receiving objects: 100% (130/130), 25.94 KiB | 0 bytes/s, done.
Resolving deltas: 100% (58/58), done.
Checking connectivity... done.
sam@x260:~/Workspaces$ cd teamcity-vagrant/
sam@x260:~/Workspaces/teamcity-vagrant$ sudo apt-get install vagrant
sam@x260:~/Workspaces/teamcity-vagrant$ cd files/
@ph1ee
ph1ee / hidpi.sh
Created July 7, 2016 05:50
hidpi config for Ubuntu GNOME
#!/bin/sh
# https://wiki.archlinux.org/index.php/HiDPI#How_to_use_non-whole_numbers
gsettings set org.gnome.desktop.interface scaling-factor 2
xrandr --output eDP1 --auto --scale 1.5x1.5
xrandr --output eDP1 --panning 2880x1620
@ph1ee
ph1ee / bootstrap_homeshick.sh
Created July 6, 2016 06:42 — forked from andsens/bootstrap_homeshick.sh
Script that can set up an entire user account with homeshick automatically
#!/bin/bash -ex
# Paste this into ssh
# curl -sL https://gist.github.com/andsens/2913223/raw/bootstrap_homeshick.sh | tar -xzO | /bin/bash -ex
# When forking, you can get the URL from the raw (<>) button.
### Set some command variables depending on whether we are root or not ###
# This assumes you use a debian derivate, replace with yum, pacman etc.
aptget='sudo apt-get'
chsh='sudo chsh'