Skip to content

Instantly share code, notes, and snippets.

@milancermak
milancermak / gist:4295532
Created Dec 15, 2012
Installing Ruby 1.9.2 on OS X 10.8
View gist:4295532
curl -L https://get.rvm.io | 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
milancermak / gist:4196125
Created Dec 3, 2012
killpaste bookmarklet
View gist:4196125
javascript:(function(){var%20H=["cut","copy","paste","contextmenu","mousedown"],%20Z=[],%20s="",%20j;%20function%20R(N,a){%20while%20(N[a])%20{%20Z[a]=Z[a]?Z[a]+1:1;%20N[a]=null;%20}%20}%20function%20zapEH(N)%20{%20var%20a,i,C;%20for%20(j%20in%20H)%20R(N,"on"+H[j]);%20C=N.childNodes;%20for%20(i=0;i<C.length;++i)%20zapEH(C[i]);%20}%20zapEH(document);%20for%20(j%20in%20Z)%20s%20+=%20j%20+%20"%20("%20+%20Z[j]%20+%20")\n";%20if(s)%20alert("Zapped%20event%20handlers:\n\n"+s);%20else%20alert("No%20event%20handlers%20found.");})();
@milancermak
milancermak / pre-commit.sh
Created Oct 7, 2012
Python pre-commit hook
View pre-commit.sh
#!/bin/sh
# make sure requirements.txt is up to date with every commit
# by comparing the output of pip freeze
pip freeze | diff requirements.txt - > /dev/null
if [ $? != 0 ]
then
echo "Missing python module dependencies in requirements.txt. Run 'pip freeze > requirements.txt' to update."
exit 1
fi
@milancermak
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__":
@milancermak
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",
"some-random-hash.apps.googleusercontent.com", # Client ID
"your-client-secret",
"refresh-token",
datetime.datetime.now(), # token expiry
"https://accounts.google.com/o/oauth2/token")
@milancermak
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
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="some-random-hash.apps.googleusercontent.com",
client_secret="your-client-secret",
scope="https://www.googleapis.com/auth/androidpublisher")
auth_url = flow.step1_get_authorize_url(redirect_uri="http://localhost")
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();