Skip to content

Instantly share code, notes, and snippets.

@gingerBill
gingerBill / defer.cpp
Last active November 20, 2022 17:45
Golang Defer in C++
////////////////////////////////////////////////////////////////
//
// Defer statement
// - Akin to D's SCOPE_EXIT or similar to Go's defer but scope-based
//
////////////////////////////////////////////////////////////////
#if defined(__cplusplus)
extern "C++" {
// NOTE(bill): Stupid fucking templates
template <typename T> struct gbRemove_Reference { typedef T Type; };
@jquacinella
jquacinella / badUsername.py
Last active July 15, 2021 17:18
List / Set of Bad Usernames
import pickle
# Create initial list by merging some sources together
# * https://gist.github.com/caseyohara/1453705
# * http://www.ietf.org/rfc/rfc2142.txt
# * https://docs.google.com/spreadsheet/ccc?key=0At1hhL-iEnOHdGpEd0xjUnJvc2EwbVVpUUo2TkhYTlE#gid=0
# * http://blog.postbit.com/reserved-username-list.html
badNames = ["INFO","MARKETING","SALES","SUPPORT","ABUSE","NOC","SECURITY","POSTMASTER","HOSTMASTER","USENET","NEWS","WEBMASTER","WWW","UUCP","FTP","SMTP","LIST","LIST-REQUEST","admin","blog","dev","ftp","mail","pop","pop3","imap","smtp","stage","stats","status","www","beta","about","access","account","accounts","add","address","adm","admin","administration","adult","advertising","affiliate","affiliates","ajax","analytics","android","anon","anonymous","api","app","apps","archive","atom","auth","authentication","avatar","backup","banner","banners","bin","billing","blog","blogs","board","bot","bots","business","chat","cache","cadastro","calendar","campaign","careers","cgi","client","cliente","code"
@fritzy
fritzy / 1_triggers.sql
Last active March 16, 2025 15:06
Get table change notifications from Postgres as JSON
CREATE OR REPLACE FUNCTION table_update_notify() RETURNS trigger AS $$
DECLARE
id bigint;
BEGIN
IF TG_OP = 'INSERT' OR TG_OP = 'UPDATE' THEN
id = NEW.id;
ELSE
id = OLD.id;
END IF;
PERFORM pg_notify('table_update', json_build_object('table', TG_TABLE_NAME, 'id', id, 'type', TG_OP)::text);
@DimaVartanian
DimaVartanian / CrashlyticsSwift.Swift
Last active June 8, 2019 10:16
Crashlytics CLS_LOG() in Swift
//
// Created by Dima Vartanian on 10/29/15.
//
import Foundation
import Crashlytics
// this method gives us pretty much the same functionality as the CLS_LOG macro, but written as a Swift function, the only differences are that we have to use array syntax for the argument list and that we don't get see if the method being called is a class method or an instance method. We also have to define the DEBUG compiler flag with -D DEBUG.
/// Usage:
///
@natecook1000
natecook1000 / NSScanner+Swift.swift
Created March 3, 2015 20:13
Swift-friendly NSScanner methods
// NSScanner+Swift.swift
// A set of Swift-idiomatic methods for NSScanner
//
// (c) 2015 Nate Cook, licensed under the MIT license
import Foundation
extension NSScanner {
// MARK: Strings
func catOptionals<T,S where S:SequenceType, S.Generator.Element == Optional<T>>(optionals: S) -> [T] {
return reduce(optionals, []) { (acc, value: T?) -> [T] in
switch value {
case let .Some(v): return acc + [v]
default: return acc
}
}
}
@ucarion
ucarion / each_cons.rs
Created December 22, 2014 23:37
Rust each_cons
#![feature(slicing_syntax)]
use std::collections::RingBuf;
fn main() {
let xs = &[1i, 2i, 3i, 4i, 5i];
let mut iter = EachCons { iter: xs.iter(), n: 3, buffer: RingBuf::new() };
for x in iter {
println!("{}", x);
@westerlund
westerlund / gif.swift
Created December 22, 2014 17:07
Create an animated gif in swift
func createGIF(with images: [UIImage], loopCount: Int = 0, frameDelay: Double, callback: (data: NSData?, error: NSError?) -> ()) {
let fileProperties = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFLoopCount as String: loopCount]]
let frameProperties = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFDelayTime as String: frameDelay]]
let documentsDirectory = NSTemporaryDirectory()
let url = NSURL(fileURLWithPath: documentsDirectory)?.URLByAppendingPathComponent("animated.gif")
if let url = url {
let destination = CGImageDestinationCreateWithURL(url, kUTTypeGIF, UInt(images.count), nil)
CGImageDestinationSetProperties(destination, fileProperties)
@mattt
mattt / NSDecimalNumber.swift
Last active April 1, 2023 00:06
NSDecimalNumber Additions for Swift
import Foundation
// MARK: - Comparable
extension NSDecimalNumber: Comparable {}
public func ==(lhs: NSDecimalNumber, rhs: NSDecimalNumber) -> Bool {
return lhs.compare(rhs) == .OrderedSame
}
@curtismcmullan
curtismcmullan / setup_selenium.sh
Last active May 2, 2023 22:56
Setup Selenium Server on Ubuntu 14.04
#!/bin/bash
# Following the guide found at this page
# http://programmingarehard.com/2014/03/17/behat-and-selenium-in-vagrant.html
echo "\r\nUpdating system ...\r\n"
sudo apt-get update
# Create folder to place selenium in