Skip to content

Instantly share code, notes, and snippets.

View kineticac's full-sized avatar

Arthur Chang kineticac

View GitHub Profile
@kineticac
kineticac / TargetDisplay.scpt
Last active October 6, 2022 09:40
Using iMac as a target display for MacBook
do shell script "ssh username@IPaddress '~/Dropbox/code/target-display/targetdisplay.sh'"

Keybase proof

I hereby claim:

  • I am kineticac on github.
  • I am artchang (https://keybase.io/artchang) on keybase.
  • I have a public key ASDwl6uPvgFTVkxhjbV-3eXNz6FqmAoPbg1K8YwmmQThAQo

To claim this, I am signing this object:

@kineticac
kineticac / ViewController.swift
Created March 4, 2016 02:36
UIImageView's image does not respect ScaleAspectFit contentMode unless the image originated as a CGImage
// 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)
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)
}
}
}
}
def some_view
@majors = HobsonsMajor.where(id: [@athlete.major1, @athlete.major2, @athlete.major3])
end
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})
end
@kineticac
kineticac / application_helper.rb
Created June 5, 2013 22:20
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.
def row_divider
(render partial: 'shared/row_divider').html_safe
end
@kineticac
kineticac / athletes_controller.rb
Created April 29, 2013 22:10
Rails index_by to help order by the order of id arrays
ids = [111, 22, 332, 34, 445]
athletes = Athlete.where(:id => ids).index_by(&:id)
unless athletes.empty?
athletes = ids.map{|id| athletes[id]}
athletes.compact!
end
@kineticac
kineticac / redis.io
Created March 15, 2013 06:44
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:
ZREMRANGEBYRANK key 0 -100
@kineticac
kineticac / athlete.rb
Last active December 14, 2015 06:18
Extending an ActiveSupport::Concern in our model. The extension has the Sunspot searchable block.
class Athlete < ActiveRecord::Base
include Extensions::AthleteSearch
# rest of athlete model code
end