Skip to content

Instantly share code, notes, and snippets.

View sleibrock's full-sized avatar
🗿
Chronomaly Moai

Steven sleibrock

🗿
Chronomaly Moai
View GitHub Profile
@sleibrock
sleibrock / FizzBuzz.hs
Created July 28, 2016 22:03
FizzBuzz with Haskell
-- Fizzbuzzing
fizzBuzz True False _ = "Fizz"
fizzBuzz False True _ = "Buzz"
fizzBuzz True True _ = "FizzBuzz"
fizzBuzz _ _ x = show x
main = do
mapM_ putStrLn [fizzBuzz (three x) (five x) x | x <- [1..100]]
where
three n = n `mod` 3 == 0
@sleibrock
sleibrock / hn-whos-hiring.py
Created August 2, 2016 20:00
Search "Who's Hiring" HackerNews threads
#!/usr/bin/env python
#-*- coding: utf-8 -*-
"""
Scraping "Who's Hiring" Posts on Hackernews
Requires: BeautifulSoup4, Requests, Python 3
"""
from sys import argv
@sleibrock
sleibrock / colors.py
Created August 9, 2016 21:09
Prints all ANSI colors in your terminal
#!/usr/bin/env python
#-*- coding: utf-8 -*-
"""
Basic colors script
prints all ANSI colors from 0 to 256
to show you your term's color mapping
"""
from sys import argv
@sleibrock
sleibrock / linux-starters.md
Last active October 11, 2016 21:49
Linux Starters Guide

GNU/Linux Command Reference

Terms and Basics

UNIX = system designed at Bell Labs, created by Dennis Ritchie

Linux = derivative of UNIX, created by Linus Torvalds

Dennis Ritchie = creator of UNIX, C programming language, hero to us all

@sleibrock
sleibrock / smallest-types-in-python.py
Created October 10, 2016 17:48
Size of Types in Python
#!/usr/bin/env python
#-*- coding: utf-8 -*-
"""
Goal: To examine which type is the smallest in Python
Types used: int, float, str, list, tuple, dict, set, frozenset
None, Ellipsis, object, lambda, function, Exception
"""
def f(): return
@sleibrock
sleibrock / compute-ex.rkt
Created October 11, 2016 20:27
Approximate e^x
#lang racket
;; Compute e^x with an approximation
;; 1 + x + x^2/2! + x^3/3! + ... up to ten terms
;; No Defines were hurt in the making of this program
(for-each
(compose
displayln
(λ (s) (apply (λ (a b) (string-append a "." (substring b 0 (if (< (string-length b) 4) (string-length b) 4)))) (string-split s ".")))
number->string
@sleibrock
sleibrock / aucvosor.rkt
Created October 11, 2016 21:48
Area Under Curve / Volume of Solid of Revolution
#lang racket
;; Compute the area under a curve and the volume of the solid between L and R
;; first line is the bases, second is the exponents, third is the L and R limits
(define bases (map string->number (string-split (read-line) " ")))
(define expos (map string->number (string-split (read-line) " ")))
(define-values
(left right)
(apply values (map string->number (string-split (read-line) " "))))
@sleibrock
sleibrock / diff-folders.py
Created November 18, 2016 18:19
Copy unique files from multiple folders into a new folder
#!/usr/bin/env python
#-*- coding: utf-8 -*-
"""
Merge two folders together using a diff digest program
If a folders have multiple files of the same digest,
ignore the duplicates and proceed to copy the unique files
into a new target folder. If the folder doesn't exist,
create a new one.
@sleibrock
sleibrock / perimeter-polygon.hs
Created January 5, 2017 19:30
HackerRank find the perimeter of a polygon from a list of points
-- Enter your code here. Read input from STDIN. Print output to STDOUT
import Control.Monad (forM)
hypot :: Floating a => a -> a -> a -> a -> a
hypot lx ly rx ry = sqrt $ (((rx-lx)**2)+((ry-ly)**2))
-- Fold over a list of points, taking the Euclidean distance, and
-- rotate the next point between each call until we reach an empty list
fp :: Floating a => a -> [a] -> [[a]] -> a
fp acc (lx:ly:[]) ((rx:ry:[]):t) = fp (acc + (hypot lx ly rx ry)) [rx,ry] t
@sleibrock
sleibrock / .htaccess
Created January 6, 2017 19:40
Grad School .htaccess
# Replace single occurance of CAP with cap, then process next Rule.
RewriteRule ^([^A]*)A(.*)$ $1a$2
RewriteRule ^([^B]*)B(.*)$ $1b$2
RewriteRule ^([^C]*)C(.*)$ $1c$2
RewriteRule ^([^D]*)D(.*)$ $1d$2
RewriteRule ^([^E]*)E(.*)$ $1e$2
RewriteRule ^([^F]*)F(.*)$ $1f$2
RewriteRule ^([^G]*)G(.*)$ $1g$2
RewriteRule ^([^H]*)H(.*)$ $1h$2
RewriteRule ^([^I]*)I(.*)$ $1i$2