Skip to content

Instantly share code, notes, and snippets.

View amosshapira's full-sized avatar

Amos Shapira amosshapira

  • Sydney, Australia
View GitHub Profile
Emscripten does not work with LLVM 3.3, which is provided with Fedora 19.
Download LLVM 3.2 and Clang from http://llvm.org/releases/. Copy the clang
source code into tools\clang, and run make (but not make install).
Set LLVM_ROOT='/home/yourname/Development/llvm-3.2.src/Release+Asserts/bin' in ~./emscripten.
sudo yum install nodejs - I found that chromium installed later versions
of the v8 package, which meant that nodejs would not install. So download
Node.js from http://nodejs.org/download/.
@amosshapira
amosshapira / lastlines.c
Last active August 29, 2015 14:05
Just a silly exercise in implementing the most efficient way to print the last X lines of a file.
/* most efficient way to print the last X lines of a file.
*
* it's done using my favourite system call - mmap(2). Instead of reading the file
* from start to finish and count newlines, the program maps the file into memory and
* scans it backwards from the end, counting newline characters as it goes. When it decided
* thet it found the beginning of the X line from the end (or reached the beginning of the file)
* it prints the entire block of lines in one call.
*
* Options to improve:
* 1. Use direct call to write(2) on file descriptor 1 instead of fwrite()
@amosshapira
amosshapira / quoted-csv.awk
Created September 25, 2014 02:05
Extract double-quoted fields from CSV file using GNU Awk
#!/usr/local/bin/gawk -f
# Taken from http://stackoverflow.com/a/8949920/164137
BEGIN {
FS=","
FPAT="([^,]+)|(\"[^\"]+\")"
}
{
@amosshapira
amosshapira / ssh-copy-id
Created September 30, 2014 05:50
ssh-copy-id for mac (perhaps cross-platform)
#!/bin/sh
# Shell script to install your public key on a remote machine
# Takes the remote machine name as an argument.
# Obviously, the remote machine must accept password authentication,
# or one of the other keys in your ssh-agent, for this to work.
ID_FILE="${HOME}/.ssh/id_rsa.pub"
if [ "-i" = "$1" ]; then
@amosshapira
amosshapira / test-files-with-spinner
Created November 6, 2014 01:34
Read file names from stdin, verify that they are regular files. The nice thing about this is the in-place progress spinner
#!/bin/bash
spin='-\|/'
i=0
ceol=`tput el`
while read filename
do
if [[ -f $filename ]]
then
i=$(( (i+1) % 4 ))
@amosshapira
amosshapira / Vagrantfile
Created December 9, 2014 10:14
Vagrant file reading node dat afrom Hiera
boxes = Dir.glob("puppet/hiera/nodes/*.yaml").map {|f| YAML.load(File.read(f)) }
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
boxes.each do |attrs|
# Required attributes
boxname = attrs['box']
@amosshapira
amosshapira / trc.bash
Last active August 29, 2015 14:11
Automatically trace output file of a background job
# The following Bash function will automatically pick up the stdout (and/or stderr,
# depending on command line options) of another Bash background job and tail it
# until the given job terminates.
#
# example usage:
# $ ls -R / &> ls.out & trc
# will run recursive "ls" in the background and redirect its output to a file
# then start "tail --pid <background job pid> -F <backgroun jobs' stdout file>"
#
# The default is to tail stdout (file descriptor "1") of the given job
@amosshapira
amosshapira / gist:e614fde990da7e8cb0d4
Created December 30, 2014 01:14
Extract "userIdentity" record from CloudTrail using jshon
zcat ...CloudTrail....json.gz | jshon -e Records -a -e userIdentity
"UserData": {
"Fn::Base64": { "Fn::Join":["", [
"#!/bin/bash -ex\n",
"apt-get update\n",
"apt-get -y install python-setuptools\n",
"mkdir aws-cfn-bootstrap-latest\n",
"curl https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz | tar xz -C aws-cfn-bootstrap-latest --strip-components 1\n",
"easy_install aws-cfn-bootstrap-latest\n",
"/usr/local/bin/cfn-init --stack ", { "Ref":"AWS::StackName" }, " --resource WebServer", " --region ", { "Ref": "AWS::Region" }, "\n"
"\n",
@amosshapira
amosshapira / tc-query-params.py
Created February 13, 2015 03:38
Python script to dig through TeamCity plans for certain plan parameters
#!/usr/bin/env python
# Example usage: ./tc-query-params.py --user username --teamcity https://teamcity.server.host.name/
from __future__ import print_function
import os
import getopt
import requests
import sys
import getpass