Skip to content

Instantly share code, notes, and snippets.

Arthur Chang kineticac

Block or report user

Report or block kineticac

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
kineticac / ViewController.swift
Created Mar 4, 2016
UIImageView's image does not respect ScaleAspectFit contentMode unless the image originated as a CGImage
View ViewController.swift
// Assume these return images from disk purely as CI and CG images
let ciImage = createPureCIImage()
let cgImage = createPureCGImage()
// This fetches the imageView reference
let imageView = getUIImageView()
imageView.contentMode = .ScaleAspectFit
// this will not show aspect fit
imageView.image = UIImage(CIImage: ciImage)
View AppDelegate.swift
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let branch = Branch.getInstance()
branch.initSessionWithLaunchOptions(launchOptions, andRegisterDeepLinkHandler: { params, error in
if (error != nil) {
TrackingManager.track(eventName: "Branch failed", withProperties: ["errorMsg": error.localizedDescription, "code": "\(error.code)"], timed: false)
View some_controller.rb
def some_view
@majors = HobsonsMajor.where(id: [@athlete.major1, @athlete.major2, @athlete.major3])
View athlete_college_bookmark.rb
belongs_to :athlete
# before we create this new bookmark, we did not need to query SQL for athlete, now we do because of this new mixpanel.
# Let's assume a query lookup on athlete is 100ms. So now we have 110ms, which is more than 10x the response time.
def before_create
Mixpanel.track('some_event', {distinct_id: athlete.r_email})
kineticac / application_helper.rb
Created Jun 5, 2013
If you render the same partial over and over again, you can make a nice helper so you don't have to be so verbose.
View application_helper.rb
def row_divider
(render partial: 'shared/row_divider').html_safe
kineticac / athletes_controller.rb
Created Apr 29, 2013
Rails index_by to help order by the order of id arrays
View athletes_controller.rb
ids = [111, 22, 332, 34, 445]
athletes = Athlete.where(:id => ids).index_by(&:id)
unless athletes.empty?
athletes ={|id| athletes[id]}
kineticac /
Created Mar 15, 2013
If you have a leaderboard or just want to save a specific number of the highest scored sets in a sorted set, use ZREMRANGEBYRANK. The example below will only keep the top 100 highest scored items:
kineticac / athlete.rb
Last active Dec 14, 2015
Extending an ActiveSupport::Concern in our model. The extension has the Sunspot searchable block.
View athlete.rb
class Athlete < ActiveRecord::Base
include Extensions::AthleteSearch
# rest of athlete model code
kineticac / athlete_search.rb
Created Feb 26, 2013
Sunspot searchable block moved to extension module using ActiveSupport::Concern
View athlete_search.rb
#extend this from Athlete model
module Extensions::AthleteSearch
extend ActiveSupport::Concern
included do
searchable :auto_index => true, :auto_remove => true do
# all your searchable code
kineticac / sidekiq.rb
Created Dec 23, 2012
Here are my configs for sidekiq
View sidekiq.rb
require 'sidekiq'
require 'autoscaler/sidekiq'
require 'autoscaler/heroku_scaler'
heroku = nil
heroku =
Sidekiq.configure_server do |config|
You can’t perform that action at this time.