This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sequence Slicing | |
https://www.facebook.com/hackercup/problems.php?pid=317343604974808&round=154897681286317 | |
Let S be a sequence of N natural numbers. We can define an infinite sequence MS in the | |
following way: MS[k] = S[k mod N] + N * floor(k / N). Where k is a zero based index. | |
For example if the sequence S is {2, 1, 3} then MS would be {2, 1, 3, 5, 4, 6, 8, 7, 9, | |
11, 10, 12...} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#include <stdlib.h> | |
#include <ctype.h> | |
#define NUM_FNS 4 | |
typedef int (*fn_ptr)(const char *); | |
int to_upper(const char *str) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0. https://github.com/kennethreitz/osx-gcc-installer/downloads | |
1. Go to https://developer.apple.com/downloads/index.action | |
2. Login with a developer account, or create one | |
3. Download the latest “Command Line Tools for XCode” | |
4. Mount the dmg and run the installer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module MyModule | |
def clean_options | |
# Just an example helper method | |
# Don't want this to pollute the AR::Base namespace | |
end | |
def do_other_stuff | |
# Another helper method | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
key, type = key.split(/(?<!:):(?!:)/) | |
key.gsub('::',':') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Time | |
# See http://msdn.microsoft.com/en-us/library/system.datetime.ticks.aspx | |
TICKS_SINCE_EPOCH = Time.utc(0001,01,01).to_i * 10000000 | |
def ticks | |
to_i * 10000000 + nsec / 100 - TICKS_SINCE_EPOCH | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyTestCase < MiniTest::Unit::TestCase | |
# ... | |
WILDCARD_MATCHER = Object.new | |
def WILDCARD_MATCHER.==(other) | |
true | |
end | |
def WILDCARD_MATCHER.is_a?(klass) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mbp:godfrey t $ svn co https://github.com/chancancode/json_expressions.git | |
Error validating server certificate for 'https://github.com:443': | |
- The certificate is not issued by a trusted authority. Use the | |
fingerprint to validate the certificate manually! | |
Certificate information: | |
- Hostname: github.com | |
- Valid: from Fri, 27 May 2011 00:00:00 GMT until Mon, 29 Jul 2013 12:00:00 GMT | |
- Issuer: www.digicert.com, DigiCert Inc, US | |
- Fingerprint: ce:67:99:25:2c:ac:78:12:7d:94:b5:62:2c:31:c5:16:a6:34:73:53 | |
(R)eject, accept (t)emporarily or accept (p)ermanently? p |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mbp:godfrey json_expressions [master] $ irb -Ilib | |
>> require 'json_expressions/matcher' | |
=> true | |
>> m = JsonExpressions::Matcher.new({a: :capture_me}) | |
=> {:a=>:capture_me} | |
>> require 'json' | |
=> true | |
>> m =~ JSON.parse('{"a": 123}') | |
=> true | |
>> m.captures |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MiniTest::Spec | |
def ensure_valid(factory) | |
factory.valid? ? factory : skip | |
end | |
end |