This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'bundler/setup' | |
require 'time' | |
require 'date' | |
require 'twitter' | |
require 'fb_graph' | |
require 'pp' | |
require 'json' | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Getting AppDelegate instance anywhere in other controllers | |
// AppDelegate.h need to be included | |
YourAppDelegate *appDelegate = (YourAppDelegate*)[[UIApplication sharedApplication] delegate]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[UIApplication sharedApplication].idleTimerDisabled = YES; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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 |