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 ChopperRecursive | |
def chop(x_number, array) | |
if array.empty? or less_than_or_greater_to(x_number, array) | |
-1 | |
end | |
recurse(0, array.length - 1, x_number, array) | |
end | |
def recurse(low, high, x_number, array) |
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
$.ajax( | |
type:'GET', | |
url:"http://example.com/users/feeds/", | |
data:"format=json&id=123", | |
success:function(feed) { | |
document.write(feed); | |
}, | |
dataType:'jsonp' | |
); |
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
{ "employees" : [{ "firstname" : "John", | |
"lastname" : "Doe" }, | |
{ "firstname" : "Ann", | |
"lastname" : "Smith" } | |
{ "firstname" : "Jake", | |
"lastname" : "Hopper" } | |
] | |
} |
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
if true isnt true | |
alert "Opposite day!" | |
volume = 10 if band isnt SpinalTap | |
if car.speed < limit then accelerate() | |
alert "It's cold!" if heat < 5 | |
winner = yes if pick in [47, 92, 13] |
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
# CoffeeScript # JavaScript | |
countdown = (num for num in [10..1]) var countdown, num; | |
countdown = (function() { | |
var i, results; | |
results = []; | |
for (num = i = 10; i >= 1; num = --i) { | |
results.push(num); | |
} |
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
# A multi-line function with correct whitespace | |
func = -> | |
"bar" | |
# A function with arguments | |
times = (a, b) -> a * b | |
# Multi-argument function | |
sum = (nums...) -> |
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
├── current -> /var/www/my_app_name/releases/20150120114500/ | |
├── releases | |
│ ├── 20150080072500 | |
│ ├── 20150090083000 | |
│ ├── 20150100093500 | |
│ ├── 20150110104000 | |
│ └── 20150120114500 | |
├── repo | |
│ └── <VCS related data> | |
├── revisions.log |
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
# post request in controller | |
post '/request_form' do | |
@form = Form.build | |
Form.validate(@form, params) | |
if @form.values.map(&:error).compact.any? | |
erb :request_form | |
else | |
#continue |
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
#All our fields require presence, so we create a base class | |
class BaseValidation | |
def absent?(value) | |
value.nil? || value.empty? | |
end | |
end | |
class DateValidation < BaseValidation |
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 Form | |
GENDER_VALUES = ["Female", "Male", "Unknown"] | |
def self.build | |
{ | |
first_name: create_field(:first_name, 'First Name', create_strategy(PresenceValidation)), | |
middle_name: create_field(:middle_name, 'Middle Name', create_strategy(NoValidation)), | |
last_name: create_field(:last_name, 'Last Name', create_strategy(PresenceValidation)), | |
gender: create_field(:gender, 'Gender', create_strategy(IncludedValidation, GENDER_VALUES), GENDER_VALUES), | |
birthdate: create_field(:birthdate, 'Date Of Birth', create_strategy(DateValidation)), |
NewerOlder