Skip to content

Instantly share code, notes, and snippets.

View elliotchance's full-sized avatar
🤓
Building awesome stuff with V

Elliot Chance elliotchance

🤓
Building awesome stuff with V
View GitHub Profile
package main
import (
"fmt"
"time"
)
func BatchStrings(values <-chan string, maxItems int, maxTimeout time.Duration) chan []string {
batches := make(chan []string)
import re
import sys
import operator
def generic_sql(sql):
sql = re.sub(r"'.*?'", "?", sql, 0, re.DOTALL)
sql = re.sub(r'".*?"', "?", sql, 0, re.DOTALL)
sql = re.sub(r"`(.*?)`", '\\1', sql, 0, re.DOTALL)
sql = re.sub(r"\d[\d\.]*", "?", sql, 0, re.DOTALL)
sql = re.sub(r"\(\?(,\s*\?\)*)*", "?", sql, 0, re.DOTALL)
@elliotchance
elliotchance / transactions.py
Created February 19, 2017 08:23
Implementing all four SQL transaction isolation levels in Python
# -*- coding: utf8 -*-
from __future__ import print_function
class LockManager:
def __init__(self):
self.locks = []
def add(self, transaction, record_id):
if not self.exists(transaction, record_id):
import XCTest
import HealthKit
@testable import Stepology
class StepUnitFormatterTests: XCTestCase {
//> (0, "0 steps")
//> (1, "1 step")
//> (2, "2 steps")
//> (999, "999 steps")
//> (1000, "1,000 steps")
@elliotchance
elliotchance / generate_tests.py
Created October 9, 2016 21:21
Parameterized Tests in Swift
import sys
import re
import glob
import os
files = []
for arg in sys.argv[1:]:
if os.path.isdir(arg):
arg += "/*.swift"
@elliotchance
elliotchance / generate_tests.py
Created October 6, 2016 21:46
Parameterized tests in Swift
import sys
import re
import glob
import os
files = []
for arg in sys.argv[1:]:
if os.path.isdir(arg):
arg += "/*.swift"
import re
def to_camel_case(text):
return re.sub('[_-](.)', lambda x: x.group(1).upper(), text)
@elliotchance
elliotchance / format_duration.py
Last active September 17, 2016 16:27
Kata: Human readable duration format
def pluralize(n, word):
if n == 1:
return '%d %s' % (n, word)
return '%d %ss' % (n, word)
def format_duration(seconds):
if seconds == 0:
return "now"
@elliotchance
elliotchance / format_duration.py
Created September 17, 2016 16:18
Kata: Human readable duration format
def format_duration(seconds):
return "now"