Skip to content

Instantly share code, notes, and snippets.

# Newbie Programmer
def factorial(x)
if x == 0
return 1
else
return x * factorial(x - 1)
end
end
puts factorial(6)
puts factorial(0)
http {
...
server {
listen 80;
server_name myapp.com;
root /myapp/public;
passenger_enabled on;
}
...
}
require 'rubygems'
require 'rack-legacy'
app = proc do |env|
use Rack::Legacy::Php, 'public'
end
run app
class Offer < ActiveRecord::Base
belongs_to :offer_type
belongs_to :offer_rate
belongs_to :city
belongs_to :location
...
end
- (void)copyItems:(id)sender {
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
NSMutableArray *items = [NSMutableArray arrayWithCapacity:_selectionView.selection.count];
for (TTShapeModelObject *shp in _selectionView.selection) {
[item setObject:[NSKeyedArchiver archivedDataWithRootObject:shp] forKey:@"TTShapeModelObject"];
[items addObject:item];
}
pasteboard.items = items;
@emarashliev
emarashliev / gist:5561872
Created May 12, 2013 00:05
Explanation isEqual: and == comparison for the Objective-C mutable and immutable objects
// Set non ARC flag (-fno-objc-arc) for the execution file
// http://stackoverflow.com/questions/6646052/how-can-i-disable-arc-for-a-single-file-in-a-project
//
//
NSMutableArray *mutableArrayOrginal = [NSMutableArray arrayWithObjects:@"asdasd", nil];
NSLog(@"mutableArrayOrginal address is: %p", mutableArrayOrginal);
NSMutableArray *mutableArrayCopy = [mutableArrayOrginal copy];
NSLog(@"mutableArrayCopy address is: %p", mutableArrayCopy);
if ([mutableArrayOrginal isEqual:mutableArrayCopy]) {
@emarashliev
emarashliev / gist:6010845
Last active December 19, 2015 20:08
Get the class of calling object
NSString *sourceString = [[NSThread callStackSymbols] objectAtIndex:1];
NSCharacterSet *separatorSet = [NSCharacterSet characterSetWithCharactersInString:@" -[]+?.,"];
NSMutableArray *array = [NSMutableArray arrayWithArray:[sourceString componentsSeparatedByCharactersInSet:separatorSet]];
Class callerClass = NSClassFromString([array objectAtIndex:3]);
@emarashliev
emarashliev / gist:6699636
Created September 25, 2013 13:31
Rocket code
- (void)viewDidLoad
{
[super viewDidLoad];
NSMutableArray *resources = [[NSMutableArray alloc] init];
NSURL *URL = [NSURL URLWithString:@"http://localhost:8080"];
AFHTTPClient *manager = [[AFHTTPClient alloc] initWithBaseURL:URL];
[manager GET:@"/messages" parameters:nil success:^(NSHTTPURLResponse *response, id responseObject) {
[resources addObjectsFromArray:responseObject[@"resources"]];
@emarashliev
emarashliev / Singleton
Created November 5, 2013 12:49
Objective-c Singleton
@implementation Singleton
static id _sharedManager;
+ (instancetype)sharedManager
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_sharedManager = [[self alloc] init];
});