Skip to content

Instantly share code, notes, and snippets.

View rcdilorenzo's full-sized avatar
🙌
Working in His Kingdom (Col 3:17)

Christian Di Lorenzo rcdilorenzo

🙌
Working in His Kingdom (Col 3:17)
View GitHub Profile
@rcdilorenzo
rcdilorenzo / CentroidCalculator.m
Created February 1, 2014 18:40
Simple Obj-C function to calculate centroid of points
CGPoint centroidOfPoints(const CGPoint* points, int pointCount) {
CGPoint centroid = CGPointMake(0, 0);
double x0, y0, x1, y1, partialArea;
double signedArea = 0.0;
for (int index = 0; index < pointCount; index++) {
int nextIndex = (index == pointCount-1) ? 0 : index+1;
x0 = points[index].x;
y0 = points[index].y;
defmodule Controller.Main do
use Weber.Controller
render_when_raise :unauthorized, {:text, 401, "Unauthorized.", []}
layout false
def action(_, conn) do
{:render, [project: "simpleTodo"], []}
import Foundation
extension Int {
func timesMap(closure: (Int) -> AnyObject) -> Array<AnyObject> {
var array: AnyObject[] = []
for x in 1...self {
array += closure(x)
}
return array;
}
@rcdilorenzo
rcdilorenzo / Gulpfile.js
Created April 10, 2015 01:00
An extremely readable yet powerful gulpfile that converts an angular app to dist folder that can be served as static assets in production while having sourcemaps and live reloading in the development environment. This gulpfile was a conversion from a stock grunt yeoman config.
var gulp = require('gulp');
var concat = require('gulp-concat');
var print = require('gulp-print');
var bowerFiles = require('main-bower-files');
var filter = require('gulp-filter');
var sass = require('gulp-sass');
var flatten = require('gulp-flatten');
var jsFilter = filter('**/*.js');
var cssFilter = filter('**/*.css');
@rcdilorenzo
rcdilorenzo / rspec_conversion_helper.rb
Created July 18, 2012 16:04
Ruby Test Unit to Rspec Helper
def assert_equal(a, b)
puts "#{a}.should == #{b}"
end
def assert_not_nil(a)
puts "#{a}.should_not == nil"
end
def assert_raise(*all_args)
puts "Cannot convert assert_raise"
@rcdilorenzo
rcdilorenzo / PlayingCard.m
Created July 25, 2012 15:48
Draw Card from Image
- (void)drawFromPosition:(CGPoint)location view:(UIView *)view size:(CGFloat)size {
UIImage *cardImage = [UIImage imageNamed:[NSString stringWithFormat:@"%@%@.png", [[self.suit substringToIndex:1] lowercaseString], [[self.rank substringToIndex:1] lowercaseString]]];
UIImageView *cardImageView = [[UIImageView alloc] initWithFrame:CGRectMake(location.x, location.y, cardImage.size.width*size, cardImage.size.height*size)];
[cardImageView setImage:cardImage];
[view addSubview:cardImageView];
}
@rcdilorenzo
rcdilorenzo / modeOfArray.m
Created July 25, 2012 18:19
Find Mode of Array in Obj C
NSMutableArray *cardRanks = [[NSMutableArray alloc] init];
for (LDNPlayingCard *card in self.cards) {
[cardRanks addObject:card.rank];
}
NSCountedSet *bagOfCardRanks = [[NSCountedSet alloc] initWithArray:cardRanks];
NSString *modeOfRanks = [[NSString alloc] init];
NSUInteger highestElementCount = 0;
for (NSString *rank in bagOfCardRanks) {
if ([bagOfCardRanks countForObject:rank] > highestElementCount) {
highestElementCount = [bagOfCardRanks countForObject:rank];
@rcdilorenzo
rcdilorenzo / gist:3179889
Created July 26, 2012 02:18
IBAction for presenting modal controller with custom setup
- (IBAction)startGame:(id)sender {
LDNViewController *ldnVC = [self.storyboard instantiateViewControllerWithIdentifier:@"gameController"];
if (playerNameField.text != @"" && playerNameField.text != nil) {
ldnVC.game = [[LDNGoFishGame alloc] init];
[ldnVC.game setupWithLivePlayer:playerNameField.text];
[self presentModalViewController:ldnVC animated:YES];
}
}
@rcdilorenzo
rcdilorenzo / gist:3379731
Created August 17, 2012 15:14
Ruby-Like select for Array
Array::select = (requestedElement) ->
count = {}
array = []
for element in this
count[element] = (count[element] || 0) + 1
if count[requestedElement]
for i in [1..count[requestedElement]]
array.push(requestedElement)
return array
else
#define IMAGE_WIDTH 100.0
#define IMAGE_HEIGHT 100.0
@implementation SOMaskScrollView
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor whiteColor];
// Initialization code