Skip to content

Instantly share code, notes, and snippets.

View kreeger's full-sized avatar

Ben Kreeger kreeger

View GitHub Profile
@kreeger
kreeger / BDKCollectionIndexView.m
Created February 11, 2013 17:19
An index-title-scrubber-bar, for use with a UICollectionView (or even a PSTCollectionView). Gives a collection view the index title bar that a UITableView gets for (almost) free. A huge thank you to @yang from http://stackoverflow.com/a/14443540/194869, which saved my bacon here.
/*
* BDKCollectionIndexView.h
*/
#import <UIKit/UIKit.h>
/** The direction in which the control is oriented. Assists in determining layout values.
*/
typedef enum {
BDKCollectionIndexViewDirectionVertical = 0,

BDKCollectionIndexView

An index-title-scrubber-bar, for use with a UICollectionView (or even a PSTCollectionView). Gives a collection view the index title bar for -sectionIndexTitles that a UITableView gets for (almost) free. A huge thank you to @Yang from [this Stack Overflow post][so], which saved my bacon here.

The problem

When you're using a UITableView and you define the UITableViewDataSource method -sectionIndexTitlesForTableView:, you get a sweet right-hand-side view for scrubbing through a long table view of fields, separated by sections. The titles are the names of the sections, by default (or at least letters based on the section names).

UITableView with section index titles

@kreeger
kreeger / smart-cache.rb
Created March 11, 2013 17:54
Smart caching, the intelligent way.
# Contains better caching retrieval and storage logic.
module SmartFetch
# Intelligently caches the block if needed, or retrieves it from cache.
# @param [String] name the name of the cache key.
# @param [Hash] options options to feed to a call to `Rails.cache.write`, if required.
# @param [Block] blk anything inside of this block gets cached.
# @return [String] the contents of the cache.
def smart_fetch(name, options={}, &blk)
unless options[:force]
@kreeger
kreeger / renamespace.rb
Created March 21, 2013 12:14
Renamespaces all Obective-C-based files recursively through a directory, including both filenames and inside the file.
#!/usr/bin/env ruby
# ruby renamespace.rb OLD NEW ./dir
# Works with headers, implementations, and plists.
old_prefix, prefix, root = ARGV
def update_file(filename, opts={})
puts "Updating #{filename}."
data = File.open(filename, 'r') { |f| f.read }
@kreeger
kreeger / mysql-split-import
Last active December 17, 2015 08:08
MySQL import for split files!
#!/usr/bin/env ruby
# MySQL import for split files!
#
# Usage:
# mysql-split-import <USERNAME> <PASSWORD> <DATABASE> <BACKUP_DIR>
# mysql-split-import a_user their_password some_database /path/to/backup
username = ARGV[0]
password = ARGV[1]
require 'oauth'
require 'uri'
key = ''
secret = ''
consumer = OAuth::Consumer.new(key, secret, { site: 'http://www.tumblr.com' })
request_token = consumer.get_request_token(exclude_callback: true)
puts request_token.authorize_url
result = gets.chomp
@kreeger
kreeger / post.rb
Created June 16, 2013 19:15
Rails model with Tumblr download capabilities.
class Post < ActiveRecord::Base
include Renderable
belongs_to :posted_by, class_name: 'User'
scope :recent, -> { order('published_at desc') }
validates :title, :body, :slug, :posted_by_id, presence: true
validates :title, :slug, uniqueness: { case_sensitive: false }
@kreeger
kreeger / pod-install-post-checkout
Last active November 30, 2021 08:15
A post-checkout hook for running a pod install after a git checkout event.
#!/bin/sh
if [ $1 = 0000000000000000000000000000000000000000 ]; then
old=4b825dc642cb6eb9a060e54bf8d69288fbee4904
else
old=$1
fi
if [ -f Podfile ] && command -v pod install >/dev/null &&
git diff --name-only $old $2 | egrep -q '^Podfile$'
then
(unset GIT_DIR; exec pod install) | grep -v '^Using ' | grep -v ' is complete'
@kreeger
kreeger / passenger.conf
Created July 23, 2013 17:59
The best way to do Passenger / Apache module configs.
# /etc/apache2/mods-available/passenger.conf
PassengerRoot /usr/lib/ruby/gems/1.9.1/gems/passenger-3.0.18
PassengerRuby /usr/bin/ruby1.9.1
@kreeger
kreeger / deploy.rb
Created July 26, 2013 14:48
A Capistrano recipe for symlinking directories from shared into current/public.
set :public_directories, %w(uploads photos)
namespace :app do
desc "Symlink public directories"
task :symlink_public_directories, :roles => [:app, :db, :web] do
public_directories.each do |directory|
source = File.join(deploy_to, 'shared', directory)
destination = File.join(release_path, 'public', directory)
invoke_command "ln -nfs #{source} #{destination}", :via => run_method
end