Skip to content

Instantly share code, notes, and snippets.

View sethmills21's full-sized avatar

Seth Miller sethmills21

View GitHub Profile
@joemccann
joemccann / nginx + node setup.md
Created October 25, 2010 02:06
Set up nginx as a reverse proxy to node.js.

The idea is to have nginx installed and node installed. I will extend this gist to include how to install those as well, but at the moment, the following assumes you have nginx 0.7.62 and node 0.2.3 installed on a Linux distro (I used Ubuntu).

In a nutshell,

  1. nginx is used to serve static files (css, js, images, etc.)
  2. node serves all the "dynamic" stuff.

So for example, www.foo.com request comes and your css, js, and images get served thru nginx while everything else (the request for say index.html or "/") gets served through node.

  1. nginx listens on port 80.
@hatfinch
hatfinch / CGAffineTransformFromRectToRect.m
Created August 17, 2011 09:54
CGAffineTransformFromRectToRect (not working)
CGAffineTransform CGAffineTransformFromRectToRect(CGRect fromRect, CGRect toRect)
{
CGSize scale = CGSizeMake(toRect.size.width / fromRect.size.width, toRect.size.height / fromRect.size.height);
CGRect scaledFromRect = CGRectMake(fromRect.origin.x * scale.width, fromRect.origin.y * scale.height,
fromRect.size.width * scale.width, fromRect.size.height * scale.height);
CGSize translation = CGSizeMake(fromRect.origin.x - scaledFromRect.origin.x, fromRect.origin.y - scaledFromRect.origin.y);
return CGAffineTransformMake(scale.width, 0.0, 0.0, scale.height, translation.width, translation.height);
}
@brcosm
brcosm / Contacts.m
Created September 11, 2011 19:08
Objective-C Image for Contact in Address Book
@implementation Contacts
+ (UIImage *)imageForContactWithName:(NSString *)name {
// Create a CF string reference from the NSString pointer
CFStringRef cfName = objc_unretainedPointer(name);
UIImage *personImage = nil;
// Create a reference to the address book
ABAddressBookRef addressBook = ABAddressBookCreate();
@zeedark
zeedark / gist:1639124
Created January 19, 2012 09:55
Resize a UIButton according to its title's length.
// Resize a UIButton according to its title's length.
CGSize stringSize = [self.myButton.titleLabel.text sizeWithFont:self.myButton.titleLabel.font];
CGRect frame = self.myButton.frame;
frame.size.width = stringSize.width;
[self.myButton setFrame:frame];
@micho
micho / nginx.conf
Last active September 29, 2023 16:38 — forked from unixcharles/nginx.conf
nginx config for http/https proxy to localhost:3000
First, install nginx for mac with "brew install nginx".
Then follow homebrew's instructions to know where the config file is.
1. To use https you will need a self-signed certificate: https://devcenter.heroku.com/articles/ssl-certificate-self
2. Copy it somewhere (use full path in the example below for server.* files)
3. sudo nginx -s reload
4. Access https://localhost/
Edit /usr/local/etc/nginx/nginx.conf:
@bluebanboom
bluebanboom / stringFromTimeInterval
Created June 12, 2012 14:54
Create NSString from NSTimeInterval with format HH:MM::SS
- (NSString *)stringFromTimeInterval:(NSTimeInterval)interval
{
NSInteger ti = (NSInteger)interval;
NSInteger seconds = ti % 60;
NSInteger minutes = (ti / 60) % 60;
NSInteger hours = (ti / 3600);
NSString *time = nil;
if (hours > 0) {
time = [NSString stringWithFormat:@"%02i:%02i:%02i", hours, minutes, seconds];
}
@turtlesoupy
turtlesoupy / nginx.conf
Created July 8, 2012 21:16
node.js upstream nginx config
http {
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=one:8m max_size=3000m inactive=600m;
proxy_temp_path /var/tmp;
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
gzip_comp_level 6;
@dtrauger
dtrauger / ios-create-gradient-background
Last active June 24, 2020 14:45
Create Gradient Background for View in Objective C
// Create the colors
UIColor *topColor = [UIColor colorWithRed:50.0/255.0 green:50.0/255.0 blue:50.0/255.0 alpha:1.0];
UIColor *bottomColor = [UIColor colorWithRed:56.0/255.0 green:56.0/255.0 blue:56.0/255.0 alpha:1.0];
// Create the gradient
CAGradientLayer *theViewGradient = [CAGradientLayer layer];
theViewGradient.colors = [NSArray arrayWithObjects: (id)topColor.CGColor, (id)bottomColor.CGColor, nil];
theViewGradient.frame = theView.bounds;
//Add gradient to view
@kyktommy
kyktommy / get_friend_list.m
Created July 22, 2013 05:34
IOS - Social Framework Get Facebook Friend list
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *facebookAccountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
id options = @{
ACFacebookAppIdKey: @"403376439767549",
ACFacebookPermissionsKey: @[ @"email", @"read_friendlists"],
ACFacebookAudienceKey: ACFacebookAudienceFriends
};
[accountStore requestAccessToAccountsWithType:facebookAccountType
options:options
completion:^(BOOL granted, NSError *error) {
@carlessistare
carlessistare / tuning_nginx_nodejs
Created September 2, 2013 20:34
Tuning Nginx for heavy loading with nodejs as upstream. Short requests and a lot of concurrence.
# This number should be, at maximum, the number of CPU cores on your system.
# (since nginx doesn't benefit from more than one worker per CPU.)
worker_processes 8;
# Determines how many clients will be served by each worker process.
# (Max clients = worker_connections * worker_processes)
# "Max clients" is also limited by the number of socket connections available on the system (~64k)
# run ss -s and u'll see a timewait param
# The reason for TIMED_WAIT is to handle the case of packets arriving after the socket is closed.