Skip to content

Instantly share code, notes, and snippets.

@jinqian
jinqian / Ruby_One_Liners.rb
Last active December 11, 2015 08:49
record of interesting ruby one-liners while I study Ruby on the way
# source code from internet & Why's (Poignant) Guide to Ruby
# fibonacci by ruby one liners
fibonacci = Hash.new { |h, k| x < 2 ? k : h[k] = h[k-1] + h[k-2] }
# print something several times
5.times { print "Odelay!" }
# unless
exit unless "restaurant".include? "aura"
@jinqian
jinqian / bug.rb
Last active December 11, 2015 13:38
# scannerController.rb
def session(session, didScan:result)
if (!result.nil?)
if (!(@result==result))
@result = result.copy
@scannerSession.pause;
Dispatch::Queue.main.async{
@overlayController.scanner(self, resultFound:result)
# example
platform: iOS
pod 'Moodstocks-iOS-SDK', '~> 3.5'
def gen_bridge_metadata(headers, bs_file)
sdk_path = self.sdk('iPhoneSimulator')
includes = headers.map { |header| "-I'#{File.dirname(header)}'" }.uniq
a = sdk_version.scan(/(\d+)\.(\d+)/)[0]
sdk_version_headers = ((a[0].to_i * 10000) + (a[1].to_i * 100)).to_s
extra_flags = OSX_VERSION >= 10.7 ? '--no-64-bit' : ''
sh "RUBYOPT='' /usr/bin/gen_bridge_metadata --format complete #{extra_flags} --cflags \"-isysroot #{sdk_path} -miphoneos-version-min=#{sdk_version} -D__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__=#{sdk_version_headers} -I. #{includes.join(' ')}\" #{headers.map { |x| "\"#{x}\"" }.join(' ')} -o \"#{bs_file}\""
end
# Example of delegation in RubyMotion
class MsActivityView < UIView
attr_accessor :delegate
def initWithFrame(frame)
super
#...
@cancelButton = UIButton.alloc.init
@cancelButton.addTarget(
self,
action: :cancel,
pod 'yourpod', :podspec => "/path/to/your/podsepc"
# OR
pod "yourpod", :local => "/path/to/your/repo"
#if MS_SDK_REQUIREMENTS
/**
* Open the scanner and connect it to the database file
*/
- (BOOL)open:(NSError **)error;
/**
* Close the scanner and disconnect it from the database file
*/
Objective-C stub for message `open:' type `c@:^@' not precompiled. Make sure you properly link with the framework or library that defines this message.
@jinqian
jinqian / gist:4960822
Last active December 13, 2015 19:09
phonegap orientation
/* Declare an orientation delegate protocol somewhere */
@protocol SomeOrientationDelegate <NSObject>
(NSUInteger)supportedInterfaceOrientations;
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;
(BOOL)shouldAutorotate;
@end
//...
/* MSHandler.m */
// Dispatched as soon as the synchronization progresses
// In this method we set "shouldKeepCallback" as YES since the sync is still in progress
- (void)didSyncWithProgress:(NSNumber *)current total:(NSNumber *)total {
int percent = 100 * [current floatValue] / [total floatValue];
[self.plugin returnSyncStatus:@""
status:2
progress:percent
callback:self.callback