Skip to content

Instantly share code, notes, and snippets.

View samchandra's full-sized avatar

Samuel Chandra samchandra

View GitHub Profile
# Ways to execute a shell script in Ruby
# Example Script - Joseph Pecoraro
cmd = "echo 'hi'" # Sample string that can be used
# 1. Kernel#` - commonly called backticks - `cmd`
# This is like many other languages, including bash, PHP, and Perl
# Returns the result of the shell command
# Docs: http://ruby-doc.org/core/classes/Kernel.html#M001111
@samchandra
samchandra / gist:2004171
Created March 8, 2012 23:40
Twitter Timeline and Facebook Pages Feed Aggregator with Ruby
require 'rubygems'
require 'bundler/setup'
require 'time'
require 'date'
require 'twitter'
require 'fb_graph'
require 'pp'
require 'json'
# Twitter
@samchandra
samchandra / gist:1986447
Created March 6, 2012 14:04
logger gem usage
require 'logger'
# setup
$LOG = Logger.new("log_file_path")
$LOG.level = Logger::DEBUG
$LOG.debug "What ever you want to log"
# more elaborate, will log all params that
# go through your route/controller, use it
# read password file
password_array = CSV.parse(File.open(PASSWORD_FILE_PATH, "r"))
# find user
users = []
password_array.each do |e|
if (e[0] == (params[:login]['username']).downcase) && (e[1] == (params[:login]['password']).downcase)
users << e
end
end
// Using NSNotificationCenter to add self as an observer for the
// MPMoviePlayerPlaybackDidFinishNotification message when we finish
// playing a movie
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(myMovieFinishedCallback)
name:MPMoviePlayerPlaybackDidFinishNotification
object:theMovie];
@samchandra
samchandra / gist:611069
Created October 5, 2010 05:51
Getting AppDelegate instance in other view controllers
// Getting AppDelegate instance anywhere in other controllers
// AppDelegate.h need to be included
YourAppDelegate *appDelegate = (YourAppDelegate*)[[UIApplication sharedApplication] delegate];
@samchandra
samchandra / gist:593271
Created September 23, 2010 07:17
Performing a method after delaying it for a few seconds
// Invoking a method after a certain amount of time has passed
// This is useful to remove UIAlertView or to perform any other
// delayed operation
[self performSelector:@selector(methodToPerform) withObject:nil afterDelay:2.0f];
@samchandra
samchandra / gist:591363
Created September 22, 2010 08:30
Creating transparent UIWebView as UITableViewCell
// Creating UITableView Cell
// Transparent UIWebView
CGRect cellFrame = CGRectMake(0, 0, 320, 100);
cell = [[[UITableViewCell alloc] initWithFrame:cellFrame] autorelease];
CGRect labelFrame = CGRectMake(5,5,310,90);
UIWebView *textWebView = [[[UIWebView alloc] initWithFrame:labelFrame] autorelease];
textWebView.backgroundColor = [UIColor clearColor];
[textWebView setOpaque:NO];
[UIApplication sharedApplication].idleTimerDisabled = YES;
- (BOOL) isPowerConnected
{
// Temporarily enable battery monitoring to check battery state
[UIDevice currentDevice].batteryMonitoringEnabled = YES;
BOOL result = ([UIDevice currentDevice].batteryState != UIDeviceBatteryStateUnplugged);
[UIDevice currentDevice].batteryMonitoringEnabled = NO;
return result
}
// Use this in another method