Skip to content

Instantly share code, notes, and snippets.

function urlencode(str)
if (str) then
str = string.gsub (str, "\n", "\r\n")
str = string.gsub (str, "([^%w ])",
function (c) return string.format ("%%%02X", string.byte(c)) end)
str = string.gsub (str, " ", "+")
end
return str
end
@randombrein
randombrein / random_duration.cpp
Created November 14, 2016 14:59 — forked from elbeno/random_duration.cpp
Uniform distributions with chrono durations
#include <algorithm>
#include <array>
#include <chrono>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <random>
#include <type_traits>
@randombrein
randombrein / sinusoidal_monotonic_curve.ipynb
Created October 23, 2016 21:40
sinusoidal_monotonic_curve notebook
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
# -*- coding: utf-8 -*-
"""
Monotonic increasing sinusoidal curve with same entrance/exit angle
"""
import numpy as np
import pylab
def discrt_tan(x0, y0, x1, y1):
@randombrein
randombrein / receptionistPattern.m
Created April 5, 2015 20:22
Receiptionist patter over KVO
#import <Foundation/Foundation.h>
typedef void (^ReceptionistTask)(NSString *keyPath, id obj, NSDictionary *change);
@interface Receptionist : NSObject
+ (instancetype)receptionistForObject:(id)obj withKeyPath:(NSString*)keyPath withQueue:(NSOperationQueue*)queue withTask:(ReceptionistTask)task;
@end
@implementation Receptionist {
id _observerdObj;
/*
We have to jump through some serious hoops to get the bundle of the caller;
[self class] doesn't work reliably when our classes are generated at the runtime.
Instead, we fetch the return address, look up the container image,
and attempt to match it against a loaded bundle.
*/
NSBundle *bundle = nil;
void *p = __builtin_return_address(0);

Keybase proof

I hereby claim:

  • I am randombrein on github.
  • I am randombrein (https://keybase.io/randombrein) on keybase.
  • I have a public key whose fingerprint is 2C32 B010 07BB F5D2 9D6A 928D 5276 996E 63B2 9769

To claim this, I am signing this object:

@randombrein
randombrein / ril2srl.py
Last active November 21, 2015 11:47
sync Pocket (read it later) data with safari's reading list
import shutil
from os.path import expanduser, dirname, abspath, join, isfile
from datetime import datetime as dt
import lxml.html
from biplist import readPlist, writePlist, InvalidPlistException, NotBinaryPlistException
from time_uuid import TimeUUID
"""
TODO:
- read/unread
@randombrein
randombrein / .bash_profile
Created June 15, 2014 19:03
my awesome bashrc under mavericks
export CLICOLOR=1
export LSCOLORS=ExFxCxDxBxegedabagacadexport
export PATH="$HOME/bin:$PATH"
export PATH="/usr/local/bin:$PATH"
export PATH="/usr/local/sbin:$PATH"
alias ll='ls -l'
alias nano='nano -m -S'
alias subl="'/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl'"
@randombrein
randombrein / postbuild-testflight.sh
Last active January 1, 2016 22:39
Xcode post-build action script to send adhoc to TestFlight over Upload API.
#!/bin/bash
################################
# Xcode post-build action script
# to send adhoc to TestFlight over Upload API
#
TESTFLIGHT_BUILD=1
if [[ $TESTFLIGHT_BUILD -ne 1 ]]
then
exit