Skip to content

Instantly share code, notes, and snippets.

View lnds's full-sized avatar

Eduardo Díaz lnds

View GitHub Profile
// Sha512 in Rust
#[macro_use]
extern crate itertools;
use sha2::{Digest, Sha512};
fn main() {
let target = Sha512::new().chain(b"help").result();
let alpha = "abcdefghijklmnopqrstuvwxyz";
let col = iproduct!(alpha.chars(), alpha.chars(), alpha.chars(), alpha.chars())
.map(|(a, b, c, d)| format!("{}{}{}{}", a, b, c, d))
@lnds
lnds / bug.kt
Created May 22, 2017 19:01
A java interop bug in Kotlin
/*
** In java remove() is overloaded
** for Class ArrayList<E>
** we have:
**
** public E remove(int index)
** Removes the element at the specified position in this list.
**
** public boolean remove(Object o)
** Removes the first occurrence of the specified element from this list
@lnds
lnds / weather.go
Created March 31, 2016 15:31
Canales en go
ch := make(chan WeatherReport)
for _, city := range cities {
go fetch(city, ch) // fetch call api and put response in ch
}
for range cities {
rep := <- ch
reports = append(reports, rep)
}
@lnds
lnds / weather.rs
Created March 31, 2016 15:28
channels in rust
let (tx, rx) = mpsc::channel();
for city in cities {
let tx = tx.clone();
let city = city.clone();
thread::spawn(move || {
let report = api_call(&city, &api_key);
tx.send(report).unwrap();
});
}
let mut reports : Vec<ApiResult> = Vec::with_capacity(cities.len());
@lnds
lnds / pweather.clj
Created March 31, 2016 15:03
pmap en clojure
((print-weather (sort-reports (pmap weather-api r))))
def parFetch(cities:List[String]) : Unit = {
val reports = (cities.par map (city => apiCall(city))).toList
printReports(reports)
}
@lnds
lnds / parfor.swift
Last active March 31, 2016 14:35
Consulta en paralelo en swift
var reports = [ApiResult?]()
for i in 1...cities.count {
reports.append(nil)
}
let globalQueue = dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0)
dispatch_apply(cities.count, globalQueue) {
i in
let index = Int(i)+2 // cities start from 2
let city = cities[index]
let rep = callApi(city, apiKey:apiKey)
@lnds
lnds / gano.clj
Created January 12, 2016 02:47
gano?
(defn gano? [num sec tam]
(let [f (famas num sec) t (- (toques num sec) f)]
(println "tu ingresaste" num)
(println "resultado:" t "Toques, " f "Famas\n")
(= tam f)))
@lnds
lnds / tyf.fs
Created January 12, 2016 02:17
Toque y fama en F#
let comparar num sec =
let rec tyf ns xs ys =
match (ns, xs, ys) with
| ([], _, _) -> (0,0)
| (n::ns, x::xs, ys) ->
let (t,f) = tyf ns xs ys
if n = x then (t,f+1) else (if List.exists (fun x -> x = n) ys then (t+1,f) else (t,f))
tyf num sec sec
@lnds
lnds / tyf.erl
Created January 12, 2016 02:15
toques y famas en erlang
contar_toques_y_famas(Num,Sec) -> tyf(Num,Sec,Sec).
tyf([],_,_) -> {0,0};
tyf([HNS|TNS],[HXS|TXS],YS) ->
{T,F} = tyf(TNS,TXS,YS),
if HNS =:= HXS -> {T,F+1};
HNS =/= HXS -> {T+toque(HNS,YS),F}
end.
toque(X,XS) -> IN = lists:member(X,XS), if IN =:= true -> 1; IN =:= false -> 0 end.