Skip to content

Instantly share code, notes, and snippets.

View gertig's full-sized avatar

Andrew Gertig gertig

View GitHub Profile
@markrickert
markrickert / example_usage.rb
Last active August 29, 2015 14:03
RubyMotion In App Purchase example
def purchase_single_product(identifier)
NSLog "Starting purchase process for #{identifier}."
@iap_helper = IAPHelper.new(NSSet.setWithArray([identifier]))
@iap_helper.cancelled = cancelled_transaction
@iap_helper.success = transaction_successful
@iap_helper.request_product_info do |success, products|
if success && products.is_a?(Array) && products.count == 1
@iap_helper.buy_product(products.first)
else
@jimsynz
jimsynz / api_controller.rb
Created March 19, 2014 01:42
Ember API Token
# app/controllers/api_controller.rb
class ApiController < ApplicationController
skip_before_action :verify_authenticity_token
respond_to :json
rescue_from UserAuthenticationService::NotAuthorized, with: :not_authorized
rescue_from ActiveRecord::RecordNotFound, with: :not_found
before_filter :api_session_token_authenticate!
private
@seanlilmateus
seanlilmateus / values_for_keys_with_dictionary.rb
Last active May 12, 2018 21:43
Using Cocoa’s KVC to assign JSON keys and values to Rubymotion models <Objects>
class User
MAPPING_KEYS = Hash[ 'user_name', :name, 'total_video_count', :videosCount]
attr_accessor *MAPPING_KEYS.values, :age
def initialize(args={})
if args.is_a?(Hash)
dictionary = Hash[ args.map { |k, v| [MAPPING_KEYS.fetch(k, k) , v] } ]
setValuesForKeysWithDictionary(dictionary)
end
end
@justinweiss
justinweiss / filterable.rb
Last active January 11, 2024 07:28
Filterable
# Call scopes directly from your URL params:
#
# @products = Product.filter(params.slice(:status, :location, :starts_with))
module Filterable
extend ActiveSupport::Concern
module ClassMethods
# Call the class methods with names based on the keys in <tt>filtering_params</tt>
# with their associated values. For example, "{ status: 'delayed' }" would call
@binho
binho / index.html
Last active August 29, 2015 13:56
install app page
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!--
Instructions:
1. Get UDID of the client device via iTunes.
2. Send the device UDID to developer portal.
3. Generate a new build with the UDID of the client.
4. Archive to enterprise distribribution and save in your machine.
5. Change MyApp.plist in this file to your generate plist file, the
@peterc
peterc / methods_returning.rb
Last active October 29, 2023 03:10
Object#methods_returning - to work out which method on an object returns what we want
require 'stringio'
require 'timeout'
class Object
def methods_returning(expected, *args, &blk)
old_stdout = $>
$> = StringIO.new
methods.select do |meth|
Timeout::timeout(1) { dup.public_send(meth, *args, &blk) == expected rescue false } rescue false
@jacklynrose
jacklynrose / vertical_centering_with_vfl.rb
Created October 27, 2013 10:35
This is how I managed to hack the visual format language to center a few views vertically (most other ways put them at the top and bottom, or just the top, or just the bottom). Basically what I'm doing is saying that the top margin should be less than or equal to half the portrait height minus the total height of all the views you'll be centring…
totalCombinedViewHeight = 100
Motion::Layout.new do |layout|
layout.view view
layout.subviews "state" => @state, "action" => @action
layout.metrics "margin" => 20, "height" => 40, "halfHeight" => ((view.bounds.size.height - totalCombinedViewHeight) / 2), "halfWidth" => ((view.bounds.size.width - 100) / 2)
layout.vertical "|-(<=halfHeight)-[state]-margin-[action]-(>=halfWidth)-|"
layout.horizontal "|-margin-[state]-margin-|"
layout.horizontal "|-margin-[action]-margin-|"
end

Converting Obj-C blocks to RubyMotion

A guide on how to translate Objective-C blocks into Ruby blocks.

Ruby Lambda and Proc Syntaxes

block = lamda { |param|  ... }
block = lamda do |param|
	...
@pasiaj
pasiaj / phantomjs-linkedin.js
Created July 31, 2013 19:57
A phantomjs script to: a) Login to Linkedin.com b) Scrape all your contacts c) Visit all the contacts d) Automatically endorse all contacts' skills.
var auth = {
user: "USERNAME",
pass: "PASSWORD"
};
function ParallelRunner (list, func, runners) {
function createSlots(runners) {
var slots = [];
for (var i = 0; i < runners; i++) {
slots.push( objReturner() );
@seanlilmateus
seanlilmateus / evernote.rb
Last active January 25, 2016 19:24
ScriptingBridge with MacRuby or Rubymotion
#!/Library/RubyMotion/bin/ruby -wKUW0
# if your using MacRuby you might change this to
# => #!/usr/bin/env macruby -wKUW0
framework 'Foundation'
framework 'ScriptingBridge'
# the original is part of an arstechnica article by Ryan
# SOURCE: http://arstechnica.com/apple/2011/09/tutorial-os-x-automation-with-macruby-and-the-scripting-bridge/
# this script with get your favourite songs and create a Evernote Note # German and English