Skip to content

Instantly share code, notes, and snippets.

Will zflat

Block or report user

Report or block zflat

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@zflat
zflat / csv2vcard.rb
Created Oct 25, 2017
Simple script to split a CSV into vcard files
View csv2vcard.rb
#! /usr/bin/ruby
# coding: utf-8
#
# Split a CSV into vcard files
infile = File.new(File.join(File.expand_path(File.dirname(__FILE__)), ARGV), "r")
while (line = infile.gets)
vals = line.split( ",")
continue if vals.empty?
fname = File.join(File.expand_path(File.dirname(__FILE__)), "vcard","#{vals[0]}.vcf".gsub( " ", "").strip)
File.open(fname, "w:UTF-8") do |f|
@zflat
zflat / bit_sum.c
Last active Oct 15, 2018
sum the bits of an integer
View bit_sum.c
#include <stdio.h>
#include <stdlib.h>
unsigned long bit_sum(unsigned long n) {
return n ? (1 + bit_sum(n & (n - 1))) : 0;
}
void main(int argc, char ** argv) {
char * p;
long n;
@zflat
zflat / printer_pjl.rb
Created Jul 11, 2017
Printer Job Language sending commands
View printer_pjl.rb
#! /usr/bin/ruby
require 'socket'
# use printer IP address here
sock = TCPSocket.new('000.000.000.000', '9100')
# Start
sock.write "\u{001B}%-12345X@PJL\n"
# commands
@zflat
zflat / octocat.svg
Created Jun 9, 2017 — forked from johan/octocat.svg
Github octocat avatar, SVG format
View octocat.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@zflat
zflat / count_csv_rows.sh
Last active Mar 16, 2017
Count lines in csv files
View count_csv_rows.sh
# Count the number of rows in csv files not counting the header row
# (assuming the header has a column named "header_col")
cat *.csv | grep -w "header_col" -c -v
# recursive
find `pwd` | xargs cat | grep -w "user_id" -c -v
# also listing files in order
ls -lR --group-directories-first
@zflat
zflat / save-git-stashes.bash
Created Oct 21, 2016
Save all stashes as patch files
View save-git-stashes.bash
git stash list | awk '{b= gensub(" ", "_", "g", $0); system("git stash show -p " substr($1, 0, length($1)-1) " > ~/Desktop/" b ".diff")}'
@zflat
zflat / notes.md
Last active Aug 29, 2015
Getting freehub to run
View notes.md

Force downgrade to rubygems 1.8

  rvm rubygems latest-1.8 --force

Setup the MySQL database and user

Start the server:

  ./script/app start
@zflat
zflat / notes.md
Created Sep 5, 2014
VM of old debian image
@zflat
zflat / export_dump.sh
Last active Aug 29, 2015
MySQL database backup
View export_dump.sh
# See http://webcheatsheet.com/SQL/mysql_backup_restore.php
# Backup
mysqldump -u user -pMyPassword databasename > databasename.sql
# Restore
# http://www.thegeekstuff.com/2008/09/backup-and-restore-mysql-database-using-mysqldump/
# Drop the existing table
# Create the table
@zflat
zflat / init.el
Created May 18, 2014
emacs initialization file ( ~/.emacs.d/init.el)
View init.el
;; Configure emacs
;; Set font
;; http://askubuntu.com/questions/23603/how-to-change-font-size-in-emacs
(set-face-attribute 'default nil :height 120)
;; disable splash screen
(load "~/elisp/autoloads" 'install)
(custom-set-variables
;; custom-set-variables was added by Custom.
You can’t perform that action at this time.