Skip to content

Instantly share code, notes, and snippets.

View jdiez17's full-sized avatar

José Manuel Díez jdiez17

  • Satellite Engineer @ NanoFF, TU Berlin
  • Berlin
View GitHub Profile
package agent
import (
"encoding/json"
"fmt"
)
type Event struct {
Agent string
Source string
[global]
font = "Ubuntu Mono 13"
allow_markup = yes
format = "<b>%s %p</b>\n%b"
sort = yes
indicate_hidden = true
# geometry = "x5"
transparency = 40
idle_threshold = 0
geometry = "300x5-20+20"
module Week2 where
import Data.List (transpose)
import Control.Arrow
data Piece = King | Queen | Rook | Bishop | Knight | Pawn | Empty
deriving (Show)
data Board = Board Int Int [[Piece]]
instance Show Board where
module Fizzbuzz where
import Data.List (unlines)
fizzbuzz :: Int -> String
fizzbuzz n = case (n `mod` 3, n `mod` 5) of
(0, 0) -> "FizzBuzz"
(0, _) -> "Fizz"
(_, 0) -> "Buzz"
(_, _) -> show n
module Week5 where
-- List of numbers, lower bound, upper bound
search :: [Int] -> Int -> Int -> Maybe Int
search [] _ _ = Nothing
search (x:xs) l u
| x > l && x < u = Just x
| otherwise = search xs l u
module Problem14 where
import Control.Monad.Writer
collatzWriter :: Int -> Writer [Int] ()
collatzWriter 1 = return ()
collatzWriter n = tell [next] >> collatzWriter next
where
next
| n `mod` 2 == 0 = n `div` 2
module Problem14 where
collatzWriter :: Int -> [Int]
collatzWriter 1 = []
collatzWriter n = next : collatzWriter next
where
next
| n `mod` 2 == 0 = n `div` 2
| otherwise = 3 * n + 1
╭─jdiez@voidray ~
╰─$ ghci
GHCi, version 7.8.3: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
λ: data Player = Player { health :: Int, name :: String } deriving (Show)
λ: let player = Player 100 "José"
λ: let setHealth p h = p { health = h }
λ: let player' = setHealth player 80
var zmq = require("zmq");
sock = zmq.socket("sub");
sock.connect("ipc:///tmp/keypad.zmq");
sock.on("message", function(msg) {
console.log(msg);
});
import random
query = 'insert into employees (emp_id, first_name, surname, salary, dept_id, comm_pct) VALUES ("%s", "%s", "%s", %d, "%s", %s);'
def get_id(name, surname):
return "%s%s%02d" % (name[0], surname[0], random.randint(0, 99))
if __name__ == '__main__':
names = [line.rstrip() for line in open("first-names.txt")]
surnames = [line.rstrip() for line in open("names.txt")]