Skip to content

Instantly share code, notes, and snippets.

View fictorial's full-sized avatar

Brian Hammond fictorial

View GitHub Profile
@boctor
boctor / BaseViewController.m
Created May 5, 2011 02:08
A base view controller class that when running on the simulator in debug mode, will auto simulate a memory warning every time the view controller's viewDidAppear is called
//
// BaseViewController.m
//
// Created by Peter Boctor on 5/4/11.
//
// Copyright (c) 2011 Peter Boctor
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
@JoeOsborn
JoeOsborn / SpriteLayer.h
Created June 28, 2011 21:53
SpriteLayer, a CALayer subclass for spritesheet-based animation
//
// SpriteLayer.h
//
// Created by Joseph C Osborn on 2011.01.12.
// Copyright 2011 Universal Happy-Maker. All rights reserved.
// This code is made available under the 3-clause BSD license:
// http://www.opensource.org/licenses/BSD-3-Clause
//
#import <Foundation/Foundation.h>
@tokumine
tokumine / window_rank.sql
Created January 9, 2012 16:30
calculating windowed rank in postgresql for a scoreboard or leaderboard
-- this SQL can be used to calculate the rank of a given user in a game,
-- and the names/scores of those just above and below him.
-- This is useful in online games or citizen science projects where you
-- just want to see the 'proximity' of other users around you, not the entire global rank
-- I want to find the rank and score for user_3, and other users 3 above and 3 below.
WITH global_rank AS (
SELECT name, score, rank() OVER (ORDER BY score DESC) FROM scores
)
SELECT * FROM global_rank
@fictorial
fictorial / CCLayerPanZoomTestLayer.m
Created May 9, 2012 20:21
CCLayerPanZoom double-tap to zoom in/out with zoom-towards-point like in the Maps app
- (void) layerPanZoom: (CCLayerPanZoom *) sender
clickedAtPoint: (CGPoint) point
tapCount: (NSUInteger) tapCount
{
NSLog(@"CCLayerPanZoomTestLayer#layerPanZoom: %@ clickedAtPoint: { %f, %f }", sender, point.x, point.y);
if (tapCount == 2) {
// Toggle zooming all the way in and all the way out.
float midScale = (sender.minScale + sender.maxScale) / 2.0;
@irace
irace / BIWebViewDelegate.m
Created September 10, 2012 02:51
JavaScript/native bridge for iOS's UIWebView
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType {
NSString *urlString = [[request URL] absoluteString];
if ([urlString hasPrefix:@"js:"]) {
NSString *jsonString = [[[urlString componentsSeparatedByString:@"js:"] lastObject]
stringByReplacingPercentEscapes];
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
NSError *error;
@jhickner
jhickner / reload_chrome.sh
Created November 15, 2012 22:37
Reload Chrome then refocus iTerm
#!/bin/sh
exec <"$0" || exit; read v; read v; exec /usr/bin/osascript - "$@"; exit
-- the above is some shell trickery that lets us write the rest of
-- the file in plain applescript
tell application "Google Chrome"
activate
tell application "System Events"
tell process "Google Chrome"
BIN = ./node_modules/.bin
SRC = $(wildcard src/*.coffee)
LIB = $(SRC:src/%.coffee=lib/%.js)
build: $(LIB)
lib/%.js: src/%.coffee
@mkdir -p $(@D)
@$(BIN)/coffee -bcp $< > $@
@willurd
willurd / web-servers.md
Last active June 7, 2024 03:53
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
@dnprock
dnprock / nginx.conf
Last active June 25, 2019 18:19
meteor nginx load balance with sticky session, used by vida.io
# Sticky session module for nginx
# https://bitbucket.org/nginx-goodies/nginx-sticky-module-ng/
# nginx configure command: ./configure --with-http_ssl_module --add-module=../nginx-sticky-module-ng/ --sbin-path=/usr/local/sbin --with-http_gzip_static_module
upstream vida_node_server {
sticky path=/;
server 127.0.0.1:3000 max_fails=3 fail_timeout=30s;
server [server2]:3000 max_fails=3 fail_timeout=30s;
}
@HoraceBury
HoraceBury / backswipelib.lua
Last active April 18, 2019 12:20
BackSwipe Navigation for Composer
-- swipe library
--[[ Libraries ]]--
local composer = require("composer")
--[[ Fields ]]--
local mainstage = display.getCurrentStage()
local stage = composer.stage