Skip to content

Instantly share code, notes, and snippets.

View davelyon's full-sized avatar

Dave Lyon davelyon

View GitHub Profile
@davelyon
davelyon / iOSFonts.txt
Created December 16, 2014 23:45
iOS Font Equivalents
UIFontTextStyleHeadline
font-family: ".HelveticaNeueInterface-MediumP4"
font-weight: bold
font-style: normal
font-size: 17.00pt
UIFontTextStyleBody
font-family: ".HelveticaNeueInterface-Regular"
font-weight: normal
font-style: normal
font-size: 17.00pt
@davelyon
davelyon / NSLayoutConstraints+visualGroup.swift
Created January 22, 2015 19:54
Swift helpers for multiple visual constraints
extension NSLayoutConstraint {
public class func visualConstraintsWithMetrics(metrics: [String : CGFloat], views: [String : UIView], options: NSLayoutFormatOptions = nil, strings: String...) -> [NSLayoutConstraint] {
return map(strings, { string in
return NSLayoutConstraint.constraintsWithVisualFormat(string, options: options, metrics: metrics, views: views) as [NSLayoutConstraint]
}).reduce([], +)
}
public class func visualConstraintsWithViews(views: [String : UIView], options: NSLayoutFormatOptions = nil, strings: String...) -> [NSLayoutConstraint] {
return map(strings, { string in
alias gs='git status'
alias ga='git add'
alias gc='git commit -m'
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "⚡"
}
function parse_git_branch {
BinaryNode* BinaryNode::remove(char *n) {
int test = strcmp(n,name);
BinaryNode *temp;
if(test > 0) { //Name we're deleting is bigger
if(right != NULL){
right = right->remove(n);
return this;
}
}
"""
MIT License
----------------------------------------------------------------
Copyright (c) 2009 David Lyon
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 to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
require 'test/unit'
class Piece
def self.beats(type)
self.instance_eval do
define_method "beats_#{type}?".intern do
true
end
end
end
#banal.rb
def banal(ary)
b = c = ary
unless ary.size <= 2
b = banal(ary[0..(ary.size/2)-1])
c = banal(ary[(ary.size/2)..-1])
else
if b[0] == c[0]
# recursively compare the keys of these hashes, making sure that two has the same keys as one
one = {:id => 1, :items => [{:name => 'one'}, {:name => 'one:one'}]}
two = {:id => 2, :items => [{:name => 'two'}, {:name => 'two:two'}]}
def check_keys(hash1, hash2)
hash1.each_key do |key|
if hash1[key].is_a? Array
return hash1[key].each_index {|sub| check_keys(hash1[key][sub], hash2[key][sub])} if hash1[key].is_a? Hash
elsif hash1[key].is_a? Hash
return check_keys(hash1[key], hash2[key])
# Base class for an Item
class LibraryItem
# Type is a depricated method, undefining it will be safe
undef_method :type
# Dynamically generates Getters/Setters for class
# get_set :name, ConstClass
def self.get_set(name, klass)
define_method(name) {
instance_variable_get("@#{name}").value
public void changeTargetIfNeeded() {
if ( targetEnemy == null || targetEnemy.isDead() )
targetEnemy = getBestEnemyToAttack();
}
public BattleCharacter getBestEnemyToAttack() {
BattleCharacter temp = null;
for(int i=0; i<enemyTeam.length; i++) {
if( temp == null || getValue(enemyTeam[i].getCharacterType().toString()) < getValue(temp.getCharacterType().toString()))
if(!enemyTeam[i].isDead())