Skip to content

Instantly share code, notes, and snippets.

View springcoil's full-sized avatar

Peadar Coyle springcoil

View GitHub Profile
@springcoil
springcoil / fizzbuzz2.scala
Created January 4, 2016 16:29
A more scala like FizzBuzz
object FizzBuzz {
def mod3(x: Int) = x % 3
def mod5(x: Int) = x % 5
def main(args: Array[String]) = {
val output = (1 to 1000000).map {
case x if mod3(x) + mod5(x) == 0 => "Fizz Buzz"
case x if mod5(x) == 0 => "Buzz"
case x if mod3(x) == 0 => "Fizz"
@springcoil
springcoil / hcmc.py
Last active January 19, 2016 20:39
Hamiltonian Monte Carlo
import numpy,math
import matplotlib.pyplot as plt
import random as random
random.seed(1) # set random seed.
# Draw random samples from Salpeter IMF.
# N ... number of samples.
# alpha ... power-law index.
# M_min ... lower bound of mass interval.
@springcoil
springcoil / fizzbuzz_improved.scala
Last active December 22, 2015 20:14
An improved fizzbuzz for Joel Grus
object FizzBuzz {
def main(args: Array[String]) {
for (x <- 1 until 100001) {
if (0 == ((x%3)+(x%5))){
println("Fizz Buzz");
} else if (0 == (x%5)){
println("Buzz");
} else if (0 == (x%3)){
println("Fizz");
} else {
@springcoil
springcoil / fizzbuzz.scala
Created December 22, 2015 18:59
A simple FizzBuzz in Scala
def fizzBuzz(x:Int) = {
if (x % 15 == 0)
"FizzBuzz"
else if (x % 3 == 0)
"Fizz"
else if (x % 5 == 0)
"Buzz"
else
x
}
@springcoil
springcoil / fizzbuzz.py
Created December 21, 2015 21:18
A simple fizzbuzz in python3
def fizzbuzz(n):
if n % 3 == 0 and n % 5 == 0:
return 'FizzBuzz'
elif n % 3 == 0:
return 'Fizz'
elif n % 5 == 0:
return 'Buzz'
else:
return str(n)
@springcoil
springcoil / stock_prices_efficient.py
Created December 21, 2015 10:34
An efficient stock prices script.
def get_max_profit(stock_prices_yesterday):
# make sure we have at least 2 prices
if len(stock_prices_yesterday) < 2:
raise IndexError('Getting a profit requires at least 2 prices')
# we'll greedily update min_price and max_profit, so we initialize
# them to the first price and the first possible profit
min_price = stock_prices_yesterday[0]
max_profit = stock_prices_yesterday[1] - stock_prices_yesterday[0]
@springcoil
springcoil / luigi_emails.py
Last active December 17, 2015 20:07
experiment_with_email_luigi.py
# these modules are needed for the task
import luigi
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
from dataextract import Manager
import pandas as pd
import json
@springcoil
springcoil / Factorial2.scala
Created December 15, 2015 23:40
Really simple factorial example written in Scala
object Factorial2 {
def main(args: Array[String])
{ for (i <- 1 to 30)
println("Factorial of " + i + ": = " + factorial(i))
}
def factorial(n: BigInt): BigInt = {
if (n <= 1)
1
else
@springcoil
springcoil / luigi_email_script.py
Created December 9, 2015 17:16
A little email script to send a file via Luigi
class SendEmail(luigi.Task):
def run(self):
fromaddr = EMAIL
toaddr = EMAIL
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = "Daily Update of Cohorts"
body = "Here is the cohort update"
msg.attach(MIMEText(body, 'plain'))
@springcoil
springcoil / Inside_Airbnb_Machine_Learning.ipynb
Created December 6, 2015 13:21
Machine Learning on Inside Airbnb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.