This file contains 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
#!/usr/bin/env python | |
def combine_list(list1, list2, short=False): | |
""" | |
Accepts 2 lists and returns a combined list mapping | |
all values in list1 to values in list2. None values | |
are replaced with an empty string. | |
list1, list2: valid list objects | |
short: True or False; stop at shortest list, else longest |
This file contains 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
cubes = (function() { | |
var _i, _len, _results; | |
_results = []; | |
for (_i = 0, _len = list.length; _i < _len; _i++) { | |
num = list[_i]; | |
_results.push(math.cube(num)); | |
} | |
return _results; | |
})(); |
This file contains 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
// Credit: http://ejohn.org/blog/fast-javascript-maxmin/ | |
Array.max = function(array){ | |
return Math.max.apply(Math, array); | |
}; | |
Array.min = function(array){ | |
return Math.min.apply(Math, array); | |
}; |
This file contains 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
/* | |
* Ternary format: variable = (condition) ? true-value : false-value; | |
*/ | |
var myName = 'Ryan'; | |
// >>> 'yes' | |
(myName == 'Ryan') ? 'yes' : 'no'; |
This file contains 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
# create a new set and add values | |
myset = set() | |
myset.add(1) | |
myset.add(2) | |
myset.add(4) | |
# by default, a set returns a set Object | |
# myset = set([1, 2, 4]) | |
# use join() to parse the List into a str |
This file contains 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
// generates a random 15 character string of alphanumeric characters | |
var str = Math.random().toString(36).slice(2); |
This file contains 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
function getDaysBetween(dStartDate, dEndDate) { | |
var intOneDay = 1000 * 60 *60 * 24; | |
return Math.ceil((dEndDate.getTime() - dStartDate.getTime()) / intOneDay); | |
} |
This file contains 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
function daysInMonth(iMonth, iYear) { | |
return new Date(iYear, iMonth, 0).getDate(); | |
} |
This file contains 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
import calendar | |
print 'Print a calendar for any month!' | |
month = int(raw_input('Month (mm)? ')) | |
year = int(raw_input('Year (yyyy)? ')) | |
print '\n' | |
calendar.setfirstweekday(calendar.SUNDAY) | |
cal = calendar.monthcalendar(year, month) | |