Skip to content

Instantly share code, notes, and snippets.

View johncalvinyoung's full-sized avatar

John Calvin Young johncalvinyoung

  • RoleModel Software
View GitHub Profile
@johncalvinyoung
johncalvinyoung / gist:3179831
Created July 26, 2012 02:03
Auto-positioning hand draw code
CGFloat xOffset = 240 - (((player.hand.count*20)+52)/2);
__block CGPoint location = CGPointMake ((CGFloat) xOffset, (CGFloat) 0);
[player.hand enumerateObjectsUsingBlock:^(RMSPlayingCard *obj, NSUInteger idx, BOOL *stop) {
NSString *rank = obj.rank;
NSString *suit = obj.suit;
UIImage *cardImage = [UIImage imageNamed:[NSString stringWithFormat:@"%@%@.png", [[suit substringToIndex:1] lowercaseString], [[rank substringToIndex:1] lowercaseString]]];
UIImageView *cardView = [[UIImageView alloc] initWithFrame:CGRectMake(location.x, location.y, cardImage.size.width, cardImage.size.height)];
[cardView setImage:cardImage];
[self.handView addSubview: cardView];
@johncalvinyoung
johncalvinyoung / gist:3180228
Created July 26, 2012 04:18
Remove all subviews from a view
- (void)removeAllSubviewsFrom:(UIView *)view {
NSArray *subviews = [view subviews];
for (UIView *subview in subviews) {
[subview removeFromSuperview];
}
}
@johncalvinyoung
johncalvinyoung / gist:3184022
Created July 26, 2012 19:29
Testing End Conditions for a game of Go Fish
- (void)testEndConditionsDeck {
RMSGoFishGame *game = [RMSGoFishGame new];
[game deal];
RMSGoFishPlayer *player1 = [game.players objectAtIndex:(NSUInteger)0];
RMSGoFishPlayer *player2 = [game.players objectAtIndex:(NSUInteger)1];
RMSGoFishPlayer *player3 = [game.players objectAtIndex:(NSUInteger)2];
RMSGoFishPlayer *player4 = [game.players objectAtIndex:(NSUInteger)3];
game.deck.cards = [NSMutableArray new];
[game gameLoop];
STAssertEquals(player1.hand.count, (NSUInteger)5,@"Player 1 played after the game was over!");
@johncalvinyoung
johncalvinyoung / gist:3207142
Created July 30, 2012 14:10
Read-write for go_fish game
def save(game)
File.open(game.key, 'w') do |file|
file.write(game.to_yaml)
end
end
def retrieve(game_id)
File.open(game_id, 'r') do |file|
YAML::load(file)
end
#!/bin/bash
# CentOS rbenv system wide installation script
# Forked from https://gist.github.com/1237417
# Installs rbenv system wide on CentOS 5/6, also allows single user installs.
# Install pre-requirements
yum install -y gcc-c++ patch readline readline-devel zlib zlib-devel libyaml-devel libffi-devel openssl-devel \
make bzip2 autoconf automake libtool bison iconv-devel git-core
# Update, upgrade and install development tools:
apt-get update
apt-get -y upgrade
apt-get -y install build-essential
apt-get -y install git-core curl
apt-get -y install libssl-dev
apt-get -y install libreadline5 libreadline5-dev
apt-get -y install zlib1g zlib1g-dev
# for passenger needed
@johncalvinyoung
johncalvinyoung / unicorn
Last active December 12, 2015 06:59 — forked from shapeshed/unicorn
#!/bin/sh
set -e
# Example init script, this can be used with nginx, too,
# since nginx and unicorn accept the same signals
# Feel free to change any of the following variables for your app:
TIMEOUT=${TIMEOUT-60}
USER=your_deploy_user
APP_ROOT=/path/to/app/
CURRENT_ROOT=$APP_ROOT/current
@johncalvinyoung
johncalvinyoung / unicorn.sh
Last active December 15, 2015 19:59 — forked from 0h546f6f78696342756e4e59/gist:2636887
Gentoo startup script for unicorn
#!/sbin/runscript
# unicorn init script for Gentoo Linux
APP_ROOT=/var/www/apps/your_app
RAILS_ROOT=$APP_ROOT/current
USER=your_user
extra_commands="reload"
depend() {
Architecture: Rails 3.2, Solr 1.4 with sunspot_solr gem, Apache HTTP server as reverse proxy to
Rails app, Jquery UI
Note: I don't care about the distinction between autocomplete and autosuggest. I am implementing what some
people call autosuggest, and I'm calling it autocomplete.
Given the above existing architecture, I want to add an autocomplete field into my app for a single
attribute on a single model. It needs to be fast and secure (duh). The search target field could have
white space and the search input should allow it, e.g., if I search with "iker's gui" it should return
#!/bin/bash
### BEGIN INIT INFO
# Provides: sidekiq beta
# Required-Start: $syslog $remote_fs
# Required-Stop: $syslog $remote_fs
# Should-Start: $local_fs
# Should-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: sidekiq for fieldvault