Skip to content

Instantly share code, notes, and snippets.

View Rydgel's full-sized avatar
😂
💯 🔥

Jérôme Mahuet Rydgel

😂
💯 🔥
View GitHub Profile
@Rydgel
Rydgel / core.clj
Created June 20, 2014 14:36
Print finished World Cup match results
(ns wc.core
(:require [clj-http.client :as client]))
(defn print-matchs-over []
(let [data-request (client/get "http://worldcup.sfg.io/matches" {:as :json-strict})
completed (filter #(= (:status %) "completed") (:body data-request))]
(doseq [{home-team :home_team away-team :away_team} completed]
(println (str (:country home-team) " " (:goals home-team) " x "
(:country away-team) " " (:goals away-team))))))
@Rydgel
Rydgel / main.scala
Last active August 29, 2015 14:03
Print finished World Cup match results
import scala.concurrent.duration._
import scala.concurrent.Await
import dispatch._, Defaults._
import play.api.libs.json._
object Main {
def formatMatch(jsonMatch: JsObject): Option[String] = for {
cHome <- (jsonMatch \ "home_team" \ "country").asOpt[String]
gHome <- (jsonMatch \ "home_team" \ "goals").asOpt[Int]
cAway <- (jsonMatch \ "away_team" \ "country").asOpt[String]
@Rydgel
Rydgel / AuthenticationAction.scala
Last active August 29, 2015 14:04
HTTP Auth Action for Scala Play 2.x
package actions
import play.api.Play
import play.api.mvc._
import scala.concurrent.Future
import org.apache.commons.codec.binary.Base64.decodeBase64
object AuthenticationAction extends ActionBuilder[Request] {
-- CIS 194: Homework 1 (http://www.seas.upenn.edu/~cis194/hw/01-intro.pdf)
-- Part I - Credit Card Validation
toDigits :: Integer -> [Integer]
toDigits n
| n <= 0 = []
| otherwise = toDigits (n `div` 10) ++ [n `mod` 10]
toDigitsRev :: Integer -> [Integer]
toDigitsRev = reverse . toDigits
{-# OPTIONS_GHC -Wall #-}
-- Homework 2 - http://www.seas.upenn.edu/~cis194/spring13/hw/02-ADTs.pdf
module LogAnalysis where
import Log
parseMessage :: String -> LogMessage
parseMessage = parseWords . words
where parseWords :: [String] -> LogMessage
module Golf where
skips :: [a] -> [[a]]
skips xs = map (\(i,x) -> takeNth i x) $ zipWith (\_ b -> (b, xs)) xs [1..]
takeNth :: Int -> [a] -> [a]
takeNth n xs = [y | (i,y) <- zip [1..] xs, i `mod` n == 0]
-- Homework 3 - http://www.seas.upenn.edu/~cis194/spring13/hw/03-rec-poly.pdf
module Golf where
import Data.List
skips :: [a] -> [[a]]
skips xs = map (\(i,x) -> takeNth i x) $ zipWith (\_ b -> (b, xs)) xs [1..]
takeNth :: Int -> [a] -> [a]
-- Homework 4 - http://www.seas.upenn.edu/~cis194/spring13/hw/04-higher-order.pdf
import Data.List
-- Exercise 1: Wholemeal programming
fun1 :: [Integer] -> Integer
fun1 [] = 1
fun1 (x:xs)
| even x = (x - 2) * fun1 xs
{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE FlexibleInstances #-}
-- Homework 6 - http://www.seas.upenn.edu/~cis194/spring13/hw/05-type-classes.pdf
import ExprT
import Parser
import StackVM as VM
import qualified Data.Map as M
import Control.Monad
{-# OPTIONS_GHC -fno-warn-missing-methods #-}
{-# LANGUAGE FlexibleInstances #-}
-- Homework 6 - http://www.seas.upenn.edu/~cis194/spring13/hw/06-laziness.pdf
fib :: Integer -> Integer
fib 0 = 0
fib 1 = 1
fib n = fib (n - 1) + fib (n - 2)