Skip to content

Instantly share code, notes, and snippets.

# !!!!!!!!!!!!!!!!!!!!!!
# Leaving this for reference, but I tested and it doesn't work in this case.
# The package requires native dependencies and thus a virtual env - can't just package up the deps on their own
# and as we know site-packages within the VENV is > 250MB when unzipped, so even if you put it S3 it doesn't matter.
# Back to the drawing board! TS
# Create a new S3 bucket to contain the lambda package (I just did this manually in the UI)
# locally, package up the dependencies (excluding *their* dependencies - i.e. only what is in requirements.txt)
from functools import singledispatch
@singledispatch
def myfunction(obj):
print(‘Do something generic: {}’.format(obj))
@myfunction.register(int)
def _(num):
  print(‘Do something octal: {0:o}’.format(num))
def myfunction(arg):
if isinstance(arg, str):
print(‘Do something stringy: {}’.format(arg))
elif isinstance(arg, int):
print(‘Do something octal: {0:o}’.format(arg))
elif isinstance(arg, float):
print(‘Do something floaty: {0:.2f}’.format(arg))
else:
print(‘Do something generic: {}’.format(arg))
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
class Overloaderer
{
public:
void myFunction(std::string something)
{
@tswann
tswann / top10hogs.sh
Created January 28, 2016 11:54
Script to list top 10 big files/directories
#!/bin/sh
# Top 10 space-hogging space hogs
for i in G M K; do du -ah | grep [0-9]$i | sort -nr -k 1; done | head -n11
@tswann
tswann / soudex-udf.java
Created December 23, 2014 15:21
Soundex UDF wrapper for Hive.
@Description(name = "soundex",
value = "_FUNC_(string) - Retrieves the Soundex code for a given string.",
extended = "Example:\n"
+ " SELECT _FUNC_(input_string) FROM src;")
public final class SoundexUDF extends UDF {
public Text evaluate(final Text text) {
if (text == null) {
return null;
}

Description

This simple script will take a picture of a whiteboard and use parts of the ImageMagick library with sane defaults to clean it up tremendously.

The script is here:

#!/bin/bash
convert "$1" -morphology Convolve DoG:15,100,0 -negate -normalize -blur 0x1 -channel RBG -level 60%,91%,0.1 "$2"

Results

@tswann
tswann / NoContext.cs
Created January 28, 2014 19:06
EF GetAll method with Context tracking turned off
public IQueryable<T> GetAll<T>() where T : class
{
return _stagingContext.Set<T>().AsNoTracking().AsQueryable();
}
@tswann
tswann / AutomapperExample.cs
Created January 27, 2014 14:21
Example of using AutoMapper to convert a EF generated POCO to a CRM entity.
using AutoMapper;
using Microsoft.Xrm.Sdk;
public class AutoMapperProfile : Profile
{
protected override void Configure()
{
this.RecognizePrefixes("new_");
this.CreateMap<stg_Contact, Contact)
@tswann
tswann / git-lg-alias
Created November 14, 2013 11:03
Git lg aliases
[alias]
lg1 = log --graph --abbrev-commit --decorate --date=relative --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all
lg2 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all
lg = !"git lg1"