Skip to content

Instantly share code, notes, and snippets.

View jjaffeux's full-sized avatar

Joffrey JAFFEUX jjaffeux

View GitHub Profile
@alloy
alloy / zomg.rb
Created February 14, 2014 10:44
Some controls have internal subviews you’d want to modify, but you cannot control the class that’s used internally. This example shows extending just that singleton (the view instance) by defining the method inline. This is preferable to using ‘categories’, because those affect _all_ instances of that class.
def presentAlert
alert = UIAlertView.new
# ...
textField = alert.textFieldAtIndex(0)
# *Only for this UITextField instance*, move the leftView 4 points to the right.
def textField.leftViewRectForBounds(bounds)
CGRectOffset(super, 4, 0)
end
@mperham
mperham / gist:8463495
Created January 16, 2014 21:10
Using #join with a Sidekiq::Batch in Rails to parallelize data migration
class MoveInventoryUpdatesToS3 < ActiveRecord::Migration
def up
batch = Sidekiq::Batch.new
batch.jobs do
InventoryUpdate.where("content is not null").pluck(:id).each do |iuid|
InventoryUpdate.delay.send_to_s3(iuid)
end
end
# wait for all jobs to finish
@joenoon
joenoon / gist:5846816
Created June 23, 2013 22:44
YapModel, coming soon
class YapModel
def self.database
Dispatch.once { @database = YapDatabase.alloc.initWithPath(App.documents_path + "/yap.db") }
@database
end
def self.dbconnection
Thread.current["yap_dbconnection"] ||= WeakRef.new(new_dbconnection)
end
@rjsamson
rjsamson / Rakefile
Created May 27, 2013 01:50
Example Rubymotion menubar app
# -*- coding: utf-8 -*-
$:.unshift("/Library/RubyMotion/lib")
require 'motion/project/template/osx'
Motion::Project::App.setup do |app|
# Use `rake config' to see complete project settings.
app.name = 'MenubarApp'
app.info_plist['NSUIElement'] = 1
end
@adelevie
adelevie / custom_cell.rb
Created November 17, 2012 18:26
Programmatically customize UITableViewCells in RubyMotion
# code inspired from http://jainmarket.blogspot.com/2009/05/creating-custom-table-view-cell.html
class CustomCell < UITableViewCell
attr_accessor :primaryLabel
attr_accessor :secondaryLabel
def createLabels
@primaryLabel = UILabel.alloc.init
@michael-erasmus
michael-erasmus / Gemfile
Created September 30, 2012 16:23
ttt_attributed_label example
source "https://rubygems.org"
gem 'sugarcube'
gem 'motion-cocoapods', :git => 'https://github.com/HipByte/motion-cocoapods.git' # 1.1.4 seems broken
class MyViewController < UIViewController
include ViewTags
#by convention, these views will have tags that correspond to the order you specify them in
# :date_label:1, :name_label:2
has_view :date_label, :name_label
def loadView
views = NSBundle.mainBundle.loadNibNamed "myview", owner:self, options:nil
self.view = views[0]
@sxross
sxross / save_cancel_toolbar.rb
Created August 12, 2012 17:15
UIToolbar Subclass to Include Save and Done Buttons
class SaveCancelToolbar < UIToolbar
attr_writer :delegate
def initWithFrame frame, andTitle: title
super
items = []
spacer = UIBarButtonItem.alloc.initWithBarButtonSystemItem(UIBarButtonSystemItemFlexibleSpace, target:nil, action:nil)
@cancel_button = UIBarButtonItem.alloc.initWithBarButtonSystemItem(UIBarButtonSystemItemCancel, target:self, action:'on_cancel:')
@catwell
catwell / active.md
Last active December 21, 2023 09:47
Speakerdecks
@godfat
godfat / app_delegate.rb
Created June 15, 2012 18:58
RubyMotion
class AppDelegate
attr_accessor :window
def application(application, didFinishLaunchingWithOptions:launchOptions)
self.window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
window.rootViewController = Controller.alloc.init
window.rootViewController.wantsFullScreenLayout = true
window.makeKeyAndVisible
true
end
end