Skip to content

Instantly share code, notes, and snippets.

View tsycho's full-sized avatar

Asif tsycho

View GitHub Profile
@tsycho
tsycho / extract-yields.rb
Created February 28, 2011 15:48
Extract non-agency yields from Credit Pricing Sheet
require 'win32ole'
require 'pathname'
require 'chronic'
excel = WIN32OLE.new('Excel.Application')
excel.visible = false
# Print header line
header = %w(Date Subprime_1yr Subprime_2yr Subprime_3yr Subprime_5yr Subprime_7+yr Prime_03-04_15yrPT Prime_03-04_30yrPT Prime_03-04_5/1PT Prime_03-04_10/1PT Prime_06-07_15yrPT Prime_06-07_30yrPT Prime_06-07_5/1PT Prime_06-07_10/1PT)
puts header.join(",").gsub("_", " ")
@tsycho
tsycho / gist:1186360
Created September 1, 2011 15:06
Format all charts in FIMS style
Sub formatChartInFimsStyle()
Dim myChart As Chart
Set myChart = ActiveChart
' Set width and height
myChart.ChartArea.Height = 158
myChart.ChartArea.Width = 230
myChart.ChartArea.Format.Line.Visible = msoFalse
@tsycho
tsycho / gist:1186928
Created September 1, 2011 18:51
Convert ccyymmdd string to Excel date
=DATE(LEFT(B2,4),MID(B2,5,2),RIGHT(B2,2))
@tsycho
tsycho / Tunes.js
Created September 8, 2011 02:11
BackboneTunes example
(function($) {
window.Album = Backbone.Model.extend({
isFirstTrack: function(index) {
return index == 0;
},
isLastTrack: function(index) {
return index >= this.get('tracks').length - 1;
},
@tsycho
tsycho / factors.rb
Created September 26, 2011 19:54
Read ABX/Primex RCD files and extract factors
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 / ruby_oauth_token_generator.rb
Created March 4, 2012 04:18
Ruby Gmail OAuth token generator
require 'hmac-sha1'
require 'base64'
require 'cgi'
module OauthHelper
def URLEscape(text)
return CGI.escape(text).gsub("+", "%20")
end
@tsycho
tsycho / NestedDict.py
Created May 20, 2012 01:26
Nested (infinite) dictionary in Python
class NestedDict(dict):
def __getitem__(self, key):
if key in self: return self.get(key)
return self.setdefault(key, NestedDict())
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
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
@tsycho
tsycho / gist:5470389
Created April 26, 2013 20:57
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.
- (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;