Skip to content

Instantly share code, notes, and snippets.

@jamalhansen
jamalhansen / code-day
Last active June 17, 2018 21:43
Keep track of 100 days of code
#!/usr/bin/env node
const start = new Date(2018, 5, 6); //TODO replace this with your first day
const today = new Date(new Date().setHours(0,0,0,0));
const datediff = (x, y) => Math.round((y-x)/(1000*60*60*24));
console.log(`Started on ${start}`);
console.log(`Today is ${today}`);
console.log(`You are on day ${datediff(start, today) + 1} of #100DaysOfCode`);
##############################################
## Example 1 - play a note
play 60
##############################################
## Example 2 - play 4 random notes
4.times do
play rrand_i(60, 90)
sleep 0.5
@jamalhansen
jamalhansen / random_bag.py
Created October 16, 2015 02:25
Random bag solution from Python Thursday
# from https://www.reddit.com/r/dailyprogrammer/comments/3ofsyb/20151012_challenge_236_easy_random_bag_system/
import random
def new_bag():
bag = list("OISZLJT")
random.shuffle(bag)
return bag
def next_piece(count):
@jamalhansen
jamalhansen / vamp_num.py
Created October 16, 2015 02:21
Vampire Number solution from Python Thursday
# from https://www.reddit.com/r/dailyprogrammer/comments/3moxid/20150928_challenge_234_easy_vampire_numbers/
from functools import reduce
def is_vampire(nums):
prod = reduce(lambda x,y: x*y, nums)
prod_str = list(str(prod))
num_str = list(reduce(lambda x,y: str(x) + str(y), nums))