Skip to content

Instantly share code, notes, and snippets.

Warren Runk wrunk

Block or report user

Report or block wrunk

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
@wrunk
wrunk / user_test.go
Last active Apr 10, 2019
Golang unit test for panic scenario
View user_test.go
func TestUserFail(t *testing.T) {
func() {
defer func() {
if r := recover(); r == nil {
t.Errorf("TestUserFail should have panicked!")
}
}()
// This function should cause a panic
CreateUser(12, "hello")
@wrunk
wrunk / pre-commit
Created Oct 28, 2016
Golang git pre commit hook
View pre-commit
#!/bin/sh
#
# Note this is mostly the standard git pre-commit.sample which can be found
# in your repo's .git/hooks/ directory with golang fmt added at the bottom.
# An example hook script to verify what is about to be committed.
# Called by "git commit" with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
@wrunk
wrunk / GolangJSONCustomMarshal.go
Created Oct 12, 2016
Golang JSON Custom Marshal
View GolangJSONCustomMarshal.go
/*
In a fairly typical webapp data model you often want to send
the client different "views" of the data model.
Many database and caching tools require the base model to be quite
standard with json tags and types, so the following approach is
ideal:
Based on this blog post and SO question:
@wrunk
wrunk / xorm_jsonb_struct_field_issue.go
Created Jun 14, 2016
Golang xorm jsonb struct field issue
View xorm_jsonb_struct_field_issue.go
package main
import (
"fmt"
"github.com/go-xorm/xorm"
_ "github.com/lib/pq"
"math/rand"
"time"
)
@wrunk
wrunk / python_multiprocessing_pool_with_queues.py
Last active Mar 16, 2019
Python multiprocessing pool with queues
View python_multiprocessing_pool_with_queues.py
from multiprocessing.pool import ThreadPool as Pool
from multiprocessing import Queue as PQueue
import Queue
my_dict = {
'url1': 'url2',
'url3': 'url4',
}
my_q = PQueue()
@wrunk
wrunk / bash_profile
Created Mar 16, 2015
Some of my bashrc/profile settings
View bash_profile
#!/bin/bash
# --------------------------------------------------------------------------- #
# These are git settings from:
# http://neverstopbuilding.net/gitpro/
# --------------------------------------------------------------------------- #
#source ~/.git-completion.bash
#source ~/.git-prompt.sh
#
# Settings for python virtual envs and the python virtualenvwrapper
@wrunk
wrunk / cheatsheet.go
Last active Aug 29, 2015
Go cheatsheet
View cheatsheet.go
/* This document is for quick ref while learning golang */
// Allocating Slices
// Using slice literals
// Make a slice of strings
strs := []string{"aaa", "bbb", "ccc", "ddd"}
// Bytes
key := []byte("5e8487e6")
// Declaring a var my_slice for later makeage
@wrunk
wrunk / sharded_guid.py
Last active Aug 29, 2015
Sharded globally unique identifier mini library for python2.7
View sharded_guid.py
#!/usr/bin/env python
# Written by Warren Runk
# This file is free software in the public domain.
import base64
import random
import uuid
@wrunk
wrunk / guid_python.py
Last active Aug 29, 2015
Creating GUIDs in python using the first two chars to get a shard
View guid_python.py
#!/usr/bin/env python
# Written by Warren Runk
# This file is free software in the public domain.
import base64
import uuid
View download_appengine_logs.py
#!/usr/bin/env python
# This script is free software written by Warren Runk (warren.runk@gmail.com)
"""
This is a (hopefully) simple example of how to download your appengine logs to a normal
linux (non google or appengine) computer using remote api and logservice.
You can use appcfg.py to "request_logs" but that is not practical for real workloads
From here you can download smaller time slices of logs as necessary depending on your scale.
You can’t perform that action at this time.