Skip to content

Instantly share code, notes, and snippets.

View shayelkin's full-sized avatar

Shay Elkin shayelkin

View GitHub Profile
@shayelkin
shayelkin / fizzbuzz.rb
Last active August 23, 2020 20:26
Modulus-less fizzbuzz in Ruby
#!/usr/bin/env ruby
def fizzbuzz(n)
c = lambda {|i, s| ([nil] * i << s).cycle}
# Must first zip with a finite range, else we'd get infinite loop
Range.new(1, n).zip(c.call(2, 'Fizz'), c.call(4, 'Buzz')).map do |a,b,c|
s = "#{b}#{c}"
s.empty? ? a : s
end
end
@shayelkin
shayelkin / fizzbuzz.hs
Last active December 17, 2015 09:09
Inspiration for fizzbuzz.py
c i s = take i (repeat "") ++ [s]
fb = zipWith (++) (cycle (c 2 "Fizz")) (cycle (c 4 "Buzz"))
fizzbuzz = zipWith (\x y -> if null x then show y else x) fb [1..]
@shayelkin
shayelkin / fizzbuzz.py
Last active July 31, 2020 03:15
Modulus-less fizzbuzz
#!/usr/bin/env python
from itertools import cycle, izip
def lazy_fizzbuzz(n):
"""
Returns iterator over fizzbuzz printout, starting at 1 and ending at n (inclusive)
"""
c = lambda i, s: cycle(([''] * i) + [s])
fb = ('%s%s' % x for x in izip(c(2, 'Fizz'), c(4, 'Buzz')))
@shayelkin
shayelkin / take-timed-photo.sh
Last active December 15, 2015 14:49
Take a photo from webcam when connected to a wifi network with a given SSID. Combine with cron to have your picture taken every N minutes.
#!/bin/sh
allowed_ssid="everything"
capture_path="$HOME/captures"
# only take a photo when at work (connected to work network)
check_wireless=$(/sbin/iwconfig wlan0 | grep "ESSID:\"$allowed_ssid\"")
if [ -n "$check_wireless" ]; then
streamer -s 1280x720 -f jpeg -o "$capture_path/$(date +%Y%m%d.%H%M).jpeg"