Skip to content

Instantly share code, notes, and snippets.

View ratelimit.js
/* Use this to cause a function to fire no more than once every 'ms' milliseconds.
For example, an expensive mousemove handler:
$('body').mouseover(ratelimit(function(ev) {
// ...
}, 250));
function ratelimit(fn, ms) {
var last = (new Date()).getTime();
milancermak / gist:3450666
Created Aug 24, 2012
Google Web server application OAuth flow, step 1
View gist:3450666
from oauth2client.client import OAuth2WebServerFlow
flow = OAuth2WebServerFlow(client_id="",
auth_url = flow.step1_get_authorize_url(redirect_uri="http://localhost")
milancermak / gist:3450785
Created Aug 24, 2012
Google Web server application OAuth flow, step 2
View gist:3450785
credentials = flow.step2_exchange(code) # code from the localhost redirect
milancermak / gist:3451039
Created Aug 24, 2012
Example of creating a OAuth2Credentials with dummy access token and a working refresh token
View gist:3451039
import datetime
import httplib2
from oauth2client.client import OAuth2Credentials
credentials = OAuth2Credentials("irrelevant access token",
"", # Client ID
"refresh-token",, # token expiry
milancermak / gist:4196125
Created Dec 3, 2012
killpaste bookmarklet
View gist:4196125
milancermak / gist:4295532
Created Dec 15, 2012
Installing Ruby 1.9.2 on OS X 10.8
View gist:4295532
curl -L | bash -s stable
source ~/.rvm/scripts/rvm
rvm install 1.9.2 --reconfigure --debug -C --enable-pthread --with-gcc=clang
# ruby --version
# ruby 1.9.2p320 (2012-04-20 revision 35421) [x86_64-darwin12.2.0]
milancermak / gist:4518064
Last active Dec 11, 2015
An example of a good error message coming from an HTTP API (illustrative for
View gist:4518064
HTTP/1.1 402 Payment Required
Content-Type: application/json
"title": "End of trial",
"description": "Unfortunately, your trial period has ended. To continue using the application, you need to purchase a subscription.",
"explanation_url": "",
"trace_url": ""
milancermak / gist:5775152
Created Jun 13, 2013
Question about combining signals in ReactiveCocoa
View gist:5775152
@interface LoginViewController ()
@property (strong, nonatomic) RACSubject *textFieldReturnPressed;
@property (strong, nonatomic) UITextField *usernameTextField;
@property (strong, nonatomic) UITextField *passwordTextField;
@implementation LoginViewController
milancermak / classMethodIntrospection.swift
Created Dec 21, 2015
A way how to introspect methods in Swift at runtime
View classMethodIntrospection.swift
var methodCount: UInt32 = 0
let methods = class_copyMethodList(anInstance.dynamicType, &methodCount) // replace anInstace
for i in 0..<Int(methodCount) {
NSLog("method: \(NSStringFromSelector(method_getName(methods[i])))")
milancermak / gist:3451509
Created Aug 24, 2012
Example of validating a recurring payment from Google Play using the Web server application OAuth 2.0 flow
View gist:3451509
import datetime
import httplib2
# to see in detail what's going on, uncomment
# httplib2.debuglevel = 4
from apiclient.discovery import build
from oauth2client.client import OAuth2Credentials, OAuth2WebServerFlow
if __name__ == "__main__":