Skip to content

Instantly share code, notes, and snippets.

@jjhamshaw
jjhamshaw / gist:901902
Created April 4, 2011 16:20
FizzBuzz Quiz: Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “
# First version
def fizzbuzz num
answer = []
answer.push 'fizz' if num % 3 == 0
answer.push 'buzz' if num % 5 == 0
answer.push num if num % 3 != 0 and num % 5 != 0

Keybase proof

I hereby claim:

  • I am jjhamshaw on github.
  • I am iamhamsure (https://keybase.io/iamhamsure) on keybase.
  • I have a public key ASAw55bnCcIep3rHK-xFtBPomnfV1MDzWukpjW0oyYnoQwo

To claim this, I am signing this object:

@jjhamshaw
jjhamshaw / delete local git branches.sh
Last active September 13, 2017 13:44
scripts to clean up local git branches for a given repository
# safe delete branches
# (deletes all MERGED branches, except dev and master)
git branch --merged | grep -v "\*" | grep -v master | grep -v dev | xargs -n 1 git branch -d
# delete branches
# (deletes all branches, except dev and master)
git branch | grep -v "\*" | grep -v master | grep -v dev | xargs -n 1 git branch -D
@jjhamshaw
jjhamshaw / docker postgres connection.sh
Created September 5, 2017 14:43
connect to your docker postgres container and run psql, without having to specify a container name or ID
docker exec -it $(docker ps -q --filter "name=postgres") psql -U postgres
@jjhamshaw
jjhamshaw / etl-runner.js
Created August 17, 2017 16:36
Conceptual idea
import async from 'async';
export default class ETLRunner {
constructor(extractor, transformer, loader) {
this.extractor = extractor;
this.transformer = transformer;
this.loader = loader;
}
extract(callback) {
@jjhamshaw
jjhamshaw / open_xamarin.sh
Created February 1, 2016 16:13
open multiple instances of xamarin studio
open -n /Applications/Xamarin\ Studio.app
@jjhamshaw
jjhamshaw / gist:3305817
Created August 9, 2012 16:49
powershell db copy
task BackupTestToQaDatabase {
try {
Invoke-Sqlcmd -InputFile $copySqlDatabase -ServerInstance $sqlserver -Database $databaseToBackUp -Username $databaseUsername -Password $databasePassword -QueryTimeout 240 -ErrorAction 'Stop'
} catch {
'##teamcity[buildStatus status='FAILURE' text='Build Failed']'
}
}
@jjhamshaw
jjhamshaw / TryCatchFinally.cs
Created June 10, 2012 14:46
try, catch, finally
try
{
// code which can cause an exception
}
catch (exception_type e)
{
// code for handling the exception
}
finally
{
@jjhamshaw
jjhamshaw / ExceptionThrowingExample.cs
Created June 10, 2012 13:20
how to throw an exception
class ExceptionThrowingExample
{
public void DoSomething()
{
Console.WriteLine("Starting to do something...");
throw new Exception();
//Will never be called. The throw command terminates the program...
Console.WriteLine("...finished doing something.");
@jjhamshaw
jjhamshaw / ListFile.cs
Created June 10, 2012 12:56
exception handling example - reads a file and writes contents to the console
class ListFile
{
static void Main(string[] args)
{
var arg0 = args[0];
try
{
var counter = 0;
if (args.Length <= 0)