Skip to content

Instantly share code, notes, and snippets.

View jakehawken's full-sized avatar
🆒

Jake Hawken jakehawken

🆒
View GitHub Profile
<script>
var name, age, truth, playAgain, yesOrNo, randomNumber, guessingGame, game;
//takes yes/no input, sanitizes user input, returns yes or no
yesOrNo = function (input)
{
var output = input.toLowerCase();
while (output !== "yes" && output !== "no") //keeps re-asking you if you don't say Y or N
{
var output = (prompt("No, silly. Type 'yes' or 'no'")).toLowerCase();
<script>
var name, age, truth, playAgain, yesOrNo, randomNumber, game, newGame, unoMas;
var game = function()
{
this.playCount = 0;
//takes yes/no input, sanitizes user input, returns yes or no
this.yesOrNo = function (input)
{
var output = input.toLowerCase();
<script>
var suits = ["Clubs", "Diamonds", "Hearts", "Spades"];
var ranks = [2, 3, 4, 5, 6, 7, 8, 9, 10, "Jack", "Queen", "King", "Ace"];
function Deck()
{
this.cards = [];
this.count = function()
{
return this.cards.length();
class Heap {
private var elements : [Int]
init() {
elements = [Int]()
}
func insert(number: Int) -> Void {
if elements.count == 0 {
elements.append(0)
@jakehawken
jakehawken / HackerRank.m
Last active December 2, 2016 21:04
Objective-C solution boilerplate for HackerRank
#import <Foundation/Foundation.h>
@interface Solver : NSObject
- (void)findSolutionForInput: (NSArray)input;
@end
@interface Solver()
{
}
@end
#import <Foundation/Foundation.h>
@interface Solver : NSObject
+ (void)findSolutionForInput: (NSArray*)input;
@end
@interface Solver()
{
}
@end
@jakehawken
jakehawken / LetterCounter.m
Created February 26, 2016 06:38
Convert a string like "aabcccccbba" to one like "2a1b5c2b1a"
- (void)letterCounter:(NSString *)string {
NSMutableString *originalString = [NSMutableString stringWithString:string];
NSMutableString *outputString = [NSMutableString new];
while (originalString.length > 0)
{
unichar firstChar = [originalString characterAtIndex:0];
NSInteger characterCount = 1;
for (int i = 1; i < originalString.length; i++)
{
@jakehawken
jakehawken / LetterCounterWithOneMutableString.m
Created February 26, 2016 17:29
Convert a string like "aabcccccbba" to one like "2a1b5c2b1a" more efficiently than this one: https://gist.github.com/jakehawken/482315e0a7d07fc15b1a
- (void)letterCounter:(NSString *)originalString
{
NSMutableString *outputString = [NSMutableString new];
NSInteger stringIndex = 0;
while (stringIndex < originalString.length)
{
unichar currentChar = [originalString characterAtIndex:stringIndex];
NSInteger characterCount = 1;
for (NSInteger i = stringIndex + 1; i < originalString.length; i++)
@jakehawken
jakehawken / Rakefile
Last active June 1, 2016 17:08
Ruby script for removing focused tests, describes, and contexts in the Cedar testing framework
desc 'remove focused tests'
task :nof do
testFiles = Dir.glob("YourProjectTests/**/*.mm")
testFiles.each do |file|
newRows = []
File.open(file, 'r').each do |line|
newRows << line.gsub('fit(', 'it(').gsub('fdescribe(', 'describe(').gsub('fcontext(', 'context(')
end
contentOfArray = newRows.join
File.open(file, 'w').write contentOfArray
@jakehawken
jakehawken / NSObject+AutoMapping.m
Last active July 3, 2016 04:28
An auto-mapper for inflating custom data objects from a given NSDictionary. This is a highly dangerous / unsafe category on NSObject, mainly done just as a fun exercise to see if it could be done. Can't say I recommend you use it.
@implementation NSObject (DataMapping)
- (instancetype)initByAutoMappingFromDictionary:(NSDictionary *)dictionary
{
Class thisClass = [self class];
self = [thisClass init];
if (self)
{
[self mapDictionaryValues:dictionary];
}