Skip to content

Instantly share code, notes, and snippets.

@cghiban
cghiban / spelling2.py
Last active October 14, 2020 19:05
Spelling for beginners (it works on a mac)
import random, subprocess, time
words = [
'safe', 'wake', 'late', 'grade','cage',
'plane', 'shape', 'away', 'gray', 'pray'
]
for i in range(len(words)):
word = words[i]
@cghiban
cghiban / makefile
Created April 21, 2020 13:59
makefile for go
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
BINARY_NAME=mybinary
BINARY_UNIX=$(BINARY_NAME)_unix
all: test build
@cghiban
cghiban / main.go
Created February 13, 2020 18:52
golang json PUT example
package main
import (
"bytes"
"encoding/json"
"io/ioutil"
"log"
"net/http"
)
@cghiban
cghiban / gzip-freeze-thaw-ungzip.pl
Created February 13, 2020 17:03
gzip-freeze-thaw-ungzip
use IO::Compress::Gzip qw(gzip $GzipError);
use IO::Uncompress::Gunzip qw(gunzip $GunzipError);
use Storable qw(nfreeze thaw);
use IO::Scalar ();
my $input = "ABC" x 200 . "A" x 2000;
my $output = "";
my $gh = IO::Scalar->new(\$output);
print length($input), $/;
@cghiban
cghiban / filter_kml.py
Created September 13, 2018 20:36
remove placemarks from a kml file
# python 2
# pip instal --user pykml
from pykml import parser
# kml source: https://www.census.gov/geo/maps-data/data/kml/kml_zcta.html
kml_file = 'cb_2017_us_zcta510_500k.kml'
# zip codes in one column text file
zip_file = 'our-zipcodes.txt'
@cghiban
cghiban / pre-commit
Created May 2, 2018 14:24 — forked from hraban/pre-commit.md
Git pre-commit hook (.git/hooks/pre-commit) to prevent accidentally committing debug code (add NOCOMMIT in source comment)
#!/bin/sh
# This pre-commit hook will prevent you from committing any line (or filename) containing
# the string NOCOMMIT. Use that tag in comments around source code you want to avoid
# accidentally committing, like temporary IP addresses or debug printfs.
#
# To add it to an existing repository, save it to .git/hooks/pre-commit (or append, if
# that file already exists). Remember to make executable (chmod +x ...)
#
# To automatically add this pre-commit hook to every repository you create or clone:
@cghiban
cghiban / nicenumber.sh
Created April 19, 2018 16:55
convers long numbers into readable ones
#!/bin/bash
# usage:
# $ echo 1234567|./nicenumber.sh
# 1,234,567
# $ find .|wc -l|./nicenumber.sh
# 426,704
while read line; do
# run the number thru the comma mill
@cghiban
cghiban / delete-emails.py
Created October 11, 2017 00:40
delete email via imap
import datetime
import email
import sys
import imaplib
m = imaplib.IMAP4_SSL("email.domain.com", 993)
try:
m.login("user","abcxyz")
except Exception, e:
@cghiban
cghiban / git-workflow.md
Created September 8, 2017 19:46
A basic git workflow for centralized repositories.

Basic Workflow

Description

Different uses of git will have a different optimal workflow. This document describes a git workflow with the following characteristics:

  • It is a centralized workflow, meaning multiple developers all push to a shared repository. (As opposed to a fork-and-pull-request Github-style workflow.)
  • It is safe to use when collaborating on a feature branch with others, but requires no workflow changes when working alone. (So there's only one set of steps to remember.)
  • Some git users rely heavily on rebases, using them for any and all conflicts. This is an unhealthy coping mechanism born of past git merge trauma. This workflow relies heavily on merges, using rebase only when it is safe to do so (with commits that have yet to be pushed).
  • push --force is never needed (and may be disallowed by the remote repository.)
#/bin/sh
input=$1
fname=$(echo $input|sed -e 's/\.mp4//')
ffmpeg -v quiet -i $input -vframes 1 -an -f image2 -y $fname.jpg