Skip to content

Instantly share code, notes, and snippets.

@douglas-vaz
douglas-vaz / Dockerfile.giter8
Created Jun 13, 2019
Dockerfile for douglasvaz/giter8:0.12.0-M1
View Dockerfile.giter8
FROM openjdk:8-alpine
RUN apk --update add curl bash
RUN export CONSCRIPT_HOME=/root/.conscript
RUN curl https://raw.githubusercontent.com/n8han/conscript/master/setup.sh -o setup.sh && chmod +x setup.sh
ENV PATH="/root/.conscript/bin:${PATH}"
RUN ./setup.sh; true
@douglas-vaz
douglas-vaz / compose.scala
Created Feb 9, 2018
Scala compose monadic type
View compose.scala
implicit class OptionK[A, B](f: (A) => Option[B]) {
def composed[C](g: B => Option[C]): (A) => Option[C] = (x: A) => f(x).flatMap(g)
}
val strToInt:(String) => Option[Int] = s => if(s.matches("-?[\\d]+")) Some(s.toInt) else None
val realSqrt:(Int) => Option[Double] = x => if(x > 0) Some(Math.sqrt(x)) else None
val strToSqrt = strToInt composed realSqrt
@douglas-vaz
douglas-vaz / smallest.clj
Last active Jan 25, 2016
Least common sorted infinite sequences
View smallest.clj
(defn proc-seq [limit arg]
(drop-while #(< % limit) arg))
(defn all-same? [xs]
(let [f #(= % (first xs))]
(every? f xs)))
(defn solve [& args]
(loop [seqs args]
(let [firsts (map first seqs)]
@douglas-vaz
douglas-vaz / merge.clj
Created Jul 16, 2015
Merge sort in Clojure
View merge.clj
(ns merge-sort)
(defn split-at-middle [xs] (split-at (/ (count xs) 2) xs))
(defn merge [X Y]
(loop [ [xhead & xtail :as x] X, [yhead & ytail :as y] Y, Result []]
(if (and (not-empty x) (not-empty y))
(if (<= xhead yhead)
(recur xtail y (conj Result xhead))
(recur x ytail (conj Result yhead)))
@douglas-vaz
douglas-vaz / prime.clj
Last active Aug 29, 2015
Prime function in Clojure
View prime.clj
(defn divisible? [x y] (zero? (mod x y)))
(defn prime? [num]
(or (= num 2) (and (not (even? num)) (not-any? #(divisible? num %) (range 3 (inc (Math/sqrt num)) 2)))))
View README.mdown

A quick jQuery plugin for asynchronously embedding a gist in an HTML document.

There are a couple of ways to use it. The simpler way is replacing all Gist links in document by their embedded version:

<script>$($.gist);</script>

All links that point to a gist, or gist file will be replaced by the corresponding embedded gist, or gist file.

Gist link replacement can also be called on a container element:

View keybase.md

Keybase proof

I hereby claim:

  • I am douglas-vaz on github.
  • I am mistcrafter (https://keybase.io/mistcrafter) on keybase.
  • I have a public key whose fingerprint is 8F57 F022 A6B3 175A 5695 13C0 5B97 A84B 8B6E 4651

To claim this, I am signing this object:

@douglas-vaz
douglas-vaz / substring.md
Created Jul 23, 2014
Bruteforce substring check
View substring.md
isSubstring(String A, String B) {
    for i = 0 to len(A)-len(B) {
        j = 0;
        while j < len(B) and A[i+j] == B[j] {
            j = j + 1;
        }
        if j == len(B) {
            return True;
        }
View rsa.py
import math
def ExtendedEuclid(m, b, verbose=False):
a1, a2, a3 = 1, 0, m
b1, b2, b3 = 0, 1, b
if(verbose):
print("Q\tA1\tA2\tA3\tB1\tB2\tB3")
q = None
@douglas-vaz
douglas-vaz / matrix.py
Created Apr 21, 2014
Matrix operations in Python with a functional style
View matrix.py
#!/usr/bin/python3
'''
Copyright (c) 2014 Douglas Vaz
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is