Skip to content

Instantly share code, notes, and snippets.

View skuro's full-sized avatar

Carlo Sciolla skuro

View GitHub Profile
@skuro
skuro / website.cljs
Created November 5, 2017 15:38
Sample code from the Clojurebridge session #2
(ns nightcoders.removeme
(:require [reagent.core :as r]
[quil.core :as q]))
(enable-console-print!)
(def image-url
"https://i.pinimg.com/originals/96/cc/3a/96cc3aafba195cecfc2662acc405c699.gif")
(def clojurebridge-url
@skuro
skuro / property.py
Last active October 25, 2017 13:18
Using a property object
class Book:
def __init__(self, title, author):
self.title = title
self.author = author
def getShortDescription(self):
"""The getter for the shortDescription property"""
return self.title + ' was written by ' + self.author
@skuro
skuro / trapped_water.clj
Last active September 11, 2017 09:37
Clojure version of the water trapped between towers problem
(defn trapped-water [towers]
(let [maxes #(reductions max %) ; the seq of increasing max values found in the input seq
maxl (maxes towers) ; the seq of max heights to the left of each tower
maxr (reverse (maxes (reverse towers))) ; the seq of max heights to the right of each tower
mins (map min maxl maxr)] ; minimum highest surrounding tower per position
(reduce + (map - mins towers)))) ; sum up the trapped water per position
;; in the following, # is a tower block and ~ is trapped water:
;;
;; 10|
@skuro
skuro / tree.py
Created August 30, 2017 09:41
comments
class TreeNode:
def __init__(self, key, val, left=None, right=None, parent=None):
# key e' inutile
self.key = key
self.payload = val
self.leftChild = left
self.rightChild = right
self.parent = parent
def hasLeftChild(self):
class Node:
def __init__(self, cargo, next=None):
self.cargo = cargo
self.next = next
def __str__(self):
return str(self.cargo)
def search(self, needle):
>>> import datetime
>>> "oggi e' %s" % datetime.date.today()
"oggi e' 2017-05-04"
>>> "oggi e' %r" % datetime.date.today()
"oggi e' datetime.date(2017, 5, 4)"
@skuro
skuro / README.md
Last active March 8, 2017 20:09 — forked from Gonzih/README.md
markov-chain-meetup-dojo
@skuro
skuro / gifcast.zsh
Created January 8, 2017 15:56
You need to have imagemagick and ffmpeg installed.
gifcast () {
mkdir /tmp/gifcast
ffmpeg -i "$@" -r 10 /tmp/gifcast/gifcast%05d.png
convert -layers Optimize /tmp/gifcast/gifcast*.png gifcast.gif
rm /tmp/gifcast/gifcast*.png
rmdir /tmp/gifcast
}
(ns nono.core
(:import [javax.imageio ImageIO]
[java.io File]))
(def test-path "/Users/not-going-to-show-my-user/Downloads/sample.bmp")
(defn extract-rgb [pixel]
(let [r (bit-and 0x000000FF (bit-shift-right pixel 16))
g (bit-and 0x000000FF (bit-shift-right pixel 8))
b (bit-and 0x000000FF pixel)]
@skuro
skuro / proc.clj
Created August 24, 2016 07:57 — forked from codification/proc.clj
Clojure asynchronous process
(ns proc
(:import [java.lang ProcessBuilder])
(:use [clojure.java.io :only [reader writer]]))
(defn spawn [& args]
(let [process (-> (ProcessBuilder. args)
(.start))]
{:out (-> process
(.getInputStream)
(reader))