Skip to content

Instantly share code, notes, and snippets.

@kirk
kirk / string_contains_emoji
Last active August 29, 2015 14:25 — forked from cihancimen/string_contains_emoji
Check if an NSString contains an emoji character
- (BOOL)stringContainsEmoji:(NSString *)string {
__block BOOL returnValue = NO;
[string enumerateSubstringsInRange:NSMakeRange(0, [string length]) options:NSStringEnumerationByComposedCharacterSequences usingBlock:
^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) {
const unichar hs = [substring characterAtIndex:0];
// surrogate pair
if (0xd800 <= hs && hs <= 0xdbff) {
if (substring.length > 1) {
const unichar ls = [substring characterAtIndex:1];
@kirk
kirk / server.conf
Created December 24, 2011 03:17
NginX config for Rails 3.1 & Unicorn
upstream example_backend {
server unix:/var/www/example.com/shared/unicorn.sock;
}
server {
listen 80;
server_name example.com www.example.com;
access_log off;
error_log off;
client_max_body_size 20M;

Setup a Three Server HAPROXY/APACHE2 Setup

Demo Part One (Launch an Apache Server)

Start the demo by launching three EC2 instances then tell the audience that this will take about 3 minutes. Also explain that we not only starting the instances we are also bootstrapping it with the Chef client (Easy Peasy)...

./setupDemo.sh 

Sample Script

check process mongodb with pidfile /data/db/mongodb/mongod.lock
start program "/etc/init.d/mongodb start"
stop program "/etc/init.d/mongodb stop"
if failed port 27017 then restart
if 5 restarts within 5 cycles then timeout
check process nginx with pidfile /opt/nginx/logs/nginx.pid
start program = "/etc/init.d/nginx start"
stop program = "/etc/init.d/nginx stop"
if failed port 80 protocol HTTP request / then restart
set daemon 60
set logfile syslog facility log_daemon
set mailserver localhost
set mail-format { from: [email protected] }
set alert root@localhost
set httpd port 2812 and
allow admin:test
include /etc/monit.d/*
#!/bin/bash
# run with: curl -s http://gist.github.com/265272.txt | bash
set -e
localdir=$HOME/.mongodb
datadir=$localdir/data
conf=$localdir/mongod.conf
agentdir=$HOME/Library/LaunchAgents
agent=$agentdir/org.mongodb.mongod.plist
#! /bin/sh
### BEGIN INIT INFO
# Provides: mongodb
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Mongodb startup script
# Description: Mongodb start stop daemon sends SIGINT to terminate
# say man signal to see details
# Please check the startup params and replication options
# rails_mongo_mapper.rb
#
# Code borrowed from Kyle Banker (who borrowed from Ben Scofield) and Justin Henry
#
# To use:
# rails project_name -m http://gist.github.com/gists/252053.txt
# Clear out stuff we won't use
run "rm README"
run "rm public/index.html"