Skip to content

Instantly share code, notes, and snippets.

@tekin
tekin / .gitattributes
Last active December 2, 2024 14:23
An example .gitattributes file that will configure custom hunk header patterns for some common languages and file formats. See https://tekin.co.uk/2020/10/better-git-diff-output-for-ruby-python-elixir-and-more for more details.
# Stick this in your home directory and point your Global Git config at it by running:
#
# $ git config --global core.attributesfile ~/.gitattributes
#
# See https://tekin.co.uk/2020/10/better-git-diff-output-for-ruby-python-elixir-and-more for more details
*.c diff=cpp
*.h diff=cpp
*.c++ diff=cpp
*.h++ diff=cpp

Keybase proof

I hereby claim:

  • I am tekin on github.
  • I am tekin (https://keybase.io/tekin) on keybase.
  • I have a public key whose fingerprint is FB9F BD4D 775C E14B F481 1BB1 4AB5 9526 95A5 5C7E

To claim this, I am signing this object:

@tekin
tekin / gist:2643351
Created May 9, 2012 09:39
Coding stats
tekin@anikulapo:~/projects/crowd.fm$ rake stats
+----------------------+-------+-------+---------+---------+-----+-------+
| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |
+----------------------+-------+-------+---------+---------+-----+-------+
| Controllers | 922 | 777 | 30 | 123 | 4 | 4 |
| Helpers | 190 | 159 | 0 | 23 | 0 | 4 |
| Models | 1266 | 978 | 26 | 151 | 5 | 4 |
| Libraries | 2691 | 2051 | 23 | 250 | 10 | 6 |
| Integration tests | 1112 | 883 | 26 | 3 | 0 | 292 |
| Functional tests | 2219 | 1957 | 28 | 18 | 0 | 106 |
@tekin
tekin / some_auth_controller.rb
Created September 3, 2011 15:12
example code for doing OAuth with Twitter using the oauth gem.
def SomeAuthController < ApplicationController
def twitter_auth
request_token = twitter_consumer.get_request_token(:oauth_callback => twitter_callback_credentials_url)
session['twitter_request_token'] = request_token.token
session['twitter_request_secret'] = request_token.secret
redirect_to request_token.authorize_url
end
def twitter_callback
module AssociationDefaultAttributes
def create(attrs, &block)
super(default_attributes.merge(attrs), &block)
end
def build(attrs={}, &block)
super(default_attributes.merge(attrs), &block)
end
end
class User < ActiveRecord::Base
has_many :events, :extend => AssociationDefaultAttributes do
def default_attributes
{ :venue => proxy_owner.default_venue }
end
end
end
module AssociationDefaultAttributes
def create(attrs, &block)
@tekin
tekin / weekends.rb
Created June 6, 2011 08:30 — forked from alterisian/weekends.rb
Weekends left til the end of summer
# Author: Ian Moss aka oceanician : http://twitter.com/oceanician
# First Published: https://gist.github.com/1009253
# modulus is your friend! this works because of the way ruby
# modulus behaves when the dvidend is negative.
def friday_after(date)
date +(5 -date.cwday) % 7
end
# Returns all the Fridays between today and the date specified.
# install the facebook_api gem first
require 'rubygems'
require 'facebook_api'
FacebookApi.configure do |config|
config.api_key = 'API_KEY_HERE'
config.secret_key = 'SECRET_KEY_HERE'
end
event_info = {:name => 'Event name', :start_time => Time.now.to_i}.to_json
AF:
code: AF
name: Afghanistan
AL:
code: AL
name: Albania
DZ:
code: DZ
name: Algeria
AS:
def create
@credit_card = ActiveMerchant::Billing::CreditCard.new(params[:credit_card])
@billing_address = Address.new(params[:address])
@payment = @order.payments.create(:credit_card => @credit_card, :address => @billing_address)
if @payment.success?
redirect_to complete_order_url(@order)
elsif @payment.requires_authentication?
# A view with an iframe from which the user is redirected to the authentication page
render :action => 'three_d_iframe'
else