Skip to content

Instantly share code, notes, and snippets.

@zflat
zflat / csv2vcard.rb
Created October 25, 2017 13:18
Simple script to split a CSV into vcard files
#! /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 / printer_pjl.rb
Created July 11, 2017 20:27
Printer Job Language sending commands
#! /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 June 9, 2017 21:09 — forked from johan/octocat.svg
Github octocat avatar, SVG format
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 March 16, 2017 21:51
Count lines in csv files
# 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 October 21, 2016 16:11
Save all stashes as patch files
git stash list | awk '{b= gensub(" ", "_", "g", $0); system("git stash show -p " substr($1, 0, length($1)-1) " > ~/Desktop/" b ".diff")}'
@zflat
zflat / altair_help_files.md
Last active December 26, 2015 19:19
Altair Help Locations
  • HyperMesh overview:

[file:///C:/Program%20Files/Altair/12.0/help/hm/hmbat.htm?hypermesh.htm][1]

  • HyperMesh Tutorials

    [file:///C:/Program%20Files/Altair/12.0/help/hm/hmbat.htm?hypermesh_tutorials.htm][2]

  • HyperWorks Desktop Overview:

@zflat
zflat / gist:7117767
Created October 23, 2013 12:30
Reset-postgres-primary-key-sequence
Useful when inserting rows into postres (like when seeding data from a .sql dump) messes up the database.
http://stackoverflow.com/questions/244243/how-to-reset-postgres-primary-key-sequence-when-it-falls-out-of-sync
// Login to psql and run the following
// What is the result?
SELECT MAX(id) FROM your_table;
// Then run...
@zflat
zflat / gist:7076465
Created October 20, 2013 23:08
Git repo from central location
git clone ssh://user@domain.com/~/path_to.git
Article at: http://toroid.org/ams/git-central-repo-howto