Skip to content

Instantly share code, notes, and snippets.

Avatar

Asif tsycho

View GitHub Profile
@tsycho
tsycho / .bash_profile
Last active Jan 3, 2016
My .bash_profile
View .bash_profile
source ~/.git-completion.bash
export PS1='\u:\W\$ '
export CLICOLOR=1 #ls with colors
# export EDITOR='vim -f'
# export EDITOR='subl -w'
export PATH=/usr/local/bin:$HOME/bin:$PATH
export PATH=$PATH:/setups/homebrew/bin
View .gitconfig
[alias]
co = checkout
ci = commit
st = status
br = branch
hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
type = cat-file -t
dump = cat-file -p
[mergetool]
@tsycho
tsycho / ios_app_link_redirector.html
Created Jul 24, 2013
Load G+ app or redirect to App store link if that fails
View ios_app_link_redirector.html
@tsycho
tsycho / gist:5470389
Created Apr 26, 2013
Manual rotation and transformation of a view. Useful when a view needs to be displayed without knowing which view controller it will be a part of, eg: status/error notifications that will come on top of all other views.
View gist:5470389
- (void)reposition {
// https://developer.apple.com/library/ios/#qa/qa2010/qa1688.html
// tl;dr Only the first subview in the window receives orientation changes.
// So we apply a transform manually to rotate the view, and change the origin of the frame so
// that it remains in a top-center position for the user.
UIInterfaceOrientation orientation =
[UIApplication sharedApplication].statusBarOrientation;
UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
CGAffineTransform viewTransform = CGAffineTransformIdentity;
View ruby_oauth_callback.rb
class OAuthController < ApplicationController
def authenticate
oauth_token = params[:oauth_token]
oauth_verifier = params[:oauth_verifier]
@user = User.find_by_oauth_token(oauth_token)
if !@user
# Do something appropriate, such as a 404
else
begin
View ruby_oauth_request_token.rb
oauth_request_url, oauth_token, oauth_token_secret = generate_request_token()
# save oauth_token and oauth_token_secret to @user
redirect_to oauth_request_url
@tsycho
tsycho / NestedDict.py
Created May 20, 2012
Nested (infinite) dictionary in Python
View NestedDict.py
class NestedDict(dict):
def __getitem__(self, key):
if key in self: return self.get(key)
return self.setdefault(key, NestedDict())
@tsycho
tsycho / ruby_oauth_token_generator.rb
Created Mar 4, 2012
Ruby Gmail OAuth token generator
View ruby_oauth_token_generator.rb
require 'hmac-sha1'
require 'base64'
require 'cgi'
module OauthHelper
def URLEscape(text)
return CGI.escape(text).gsub("+", "%20")
end
@tsycho
tsycho / factors.rb
Created Sep 26, 2011
Read ABX/Primex RCD files and extract factors
View factors.rb
require "crack"
require "json"
files = File.read("files.txt").split("\n")
files.each { |filename|
filename = filename.strip
next if filename.empty?
myXML = Crack::XML.parse( File.read(filename) )
@tsycho
tsycho / Tunes.js
Created Sep 8, 2011
BackboneTunes example
View Tunes.js
(function($) {
window.Album = Backbone.Model.extend({
isFirstTrack: function(index) {
return index == 0;
},
isLastTrack: function(index) {
return index >= this.get('tracks').length - 1;
},