A guide on how to translate Objective-C blocks into Ruby blocks.
block = lamda { |param| ... }
block = lamda do |param|
...| # 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 |
| 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 |
| # 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 |
| <!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 |
| 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 |
| 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 |
| 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() ); |
| #!/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 |
| #!/bin/sh -e | |
| cd "${1-.}" | |
| for f in *; do | |
| mv "$f" "${f%.*}@2x.${f##*.}" | |
| done | |