Skip to content

Instantly share code, notes, and snippets.

@chrisallick
chrisallick / gist:3894094
Created October 15, 2012 18:11
Make client doing annoying work of calculating their time, but make server do important task of knowing when to send timestamp.
RUBY:
# push timecheck command to clients every 30 minutes for rooms where client count is greater than 0
timecheck = EM.add_periodic_timer(60*30) {
@channels.keys.each do | key |
if @channels[key][:clients].length > 0
data = { :type => "roomnotice", :special => "timecheck", :msg => "heyo!" }.to_json
@channels[key][:channel].push data
end
end
}
@chrisallick
chrisallick / gist:3942584
Created October 23, 2012 23:38
failed to build cocomotion
pallick:cocosmotion chrisallick$ rake
Build ./build/iPhoneSimulator-6.0-Development
Build vendor/cocos2d-iphone
Build settings from command line:
ARCHS = i386
CONFIGURATION_BUILD_DIR = .build
IPHONEOS_DEPLOYMENT_TARGET = 6.0
SDKROOT = iphonesimulator6.0
=== BUILD NATIVE TARGET kazmath OF PROJECT cocos2d-ios WITH CONFIGURATION Release ===
@chrisallick
chrisallick / gist:3990089
Created October 31, 2012 21:42
Autoplay audio on the ipad or iphone using webkitaudiocontext instead of audio tag
AudioSFX = function( _p, _autoplay ) {
var self = this;
var parent = _p;
this.sounds = new Array();
this.context = new webkitAudioContext();
this.autoplay = _autoplay;
this.play = function( sound ) {
Location[] points = new Location[20];
int myX, myY, myZ;
int radius = 100;
void setup() {
size( 640, 640, P3D);
//frameRate(25);
createPoints();
noFill();
strokeWeight( 1 );
class Location {
//float x, y, z;
PVector v;
float aa, ab, va, vb;
float r;
int c = 0;
boolean alive = true;
Location (float myX, float myY, float myZ, float aA, float aB, int index) {
v = new PVector( myX, myY, myZ );
@chrisallick
chrisallick / serviceparse
Created January 9, 2013 22:52
parse urls for serviceable content and adjust accordingly
Services = function( _p ) {
self = this;
parent = _p;
this.services = {
"cl.ly": "cloudapp",
"www.dropbox.com": "dropbox"
}
this.events = {
@chrisallick
chrisallick / FillCircle.m
Created January 31, 2013 05:18
This is one way to animate the filling of a circle in objective-c, does anyone know the right way?
//
// FillCircle.m
// cramera
//
// Created by Chris Allick on 1/30/13.
// Copyright (c) 2013 Chris Allick. All rights reserved.
//
#import "FillCircle.h"
@chrisallick
chrisallick / gist:4693962
Created February 1, 2013 20:36
How day do dat? Pulling vine videos from twitter based on a hashtag. create the json request, bump the script tag with object into your dom, delete dom element, parse it.
result.entities.urls[0].expanded_urlfetch = function(query) {
var script_tag = document.createElement("script");
script_tag.id = "fetcher";
script_tag.src = "https://search.twitter.com/search.json"+query+"&callback=parse";
document.body.appendChild(script_tag);
}
parse = function(data) {
document.body.removeChild(document.getElementById("fetcher"));
if( data && data.results ) {
@chrisallick
chrisallick / sendTwitter.m
Created February 4, 2013 19:25
I was having a hard time figuring out how to upload an image to Twitter with a progress callback. Turns out I wasn't far off, just needed to convert my SLRequest to an NSURLRequest and then AFNetworking(godbless you) does the rest with progress blocks.
-(void)sendTwitter {
ACAccountStore *account = [[ACAccountStore alloc] init];
ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:
ACAccountTypeIdentifierTwitter];
[account requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error) {
if (granted == YES) {
NSArray *arrayOfAccounts = [account accountsWithAccountType:accountType];
if ([arrayOfAccounts count] > 0) {
twitterAccount = [arrayOfAccounts lastObject];
@chrisallick
chrisallick / gist:4710587
Created February 4, 2013 23:04
Run a piece of code after a delay. I'm sure an Objective-C nerd loses it's wings every time i use this, but god damn is that useful as shiiiiit. Even worse, im iterating over subviews to destroy them.
double delayInSeconds = 1.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
//code to be executed on the main queue after delay
sendButton.frame = CGRectMake(0, self.view.frame.size.height-(191*.5), 640*.5, 191*.5);
CGRect frame = sendingLabel.frame;
frame.origin.y = -30 - frame.size.height;
[sendingLabel setFrame:frame];
for (id subview in self.view.subviews) {