Skip to content

Instantly share code, notes, and snippets.

@enriclluelles
enriclluelles / main.go
Created January 27, 2017 02:44
Trigger reset by peer
package main
import (
"fmt"
"net"
"log"
)
func main() {
addr, _ := net.ResolveTCPAddr("tcp", ":3456")
@enriclluelles
enriclluelles / dyndns.py
Created February 22, 2016 23:21
poor man's dyndns using route53
from __future__ import print_function
import boto3
import botocore
import requests
import re
import sys
ip = requests.get("https://api.ipify.org").text
if not re.match(r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$",ip):
print("Fail getting the ip", file=sys.stderr)
@enriclluelles
enriclluelles / keybase.md
Created February 18, 2016 16:40
keybase.md

Keybase proof

I hereby claim:

  • I am enriclluelles on github.
  • I am enriclluelles (https://keybase.io/enriclluelles) on keybase.
  • I have a public key whose fingerprint is A0ED 7FB2 DE48 E28D 3864 D6C8 05E7 B98A E739 EED1

To claim this, I am signing this object:

function national_flag(a, p) {
function swap(i, j) {
// console.log("swapping a[" + i + "]:" + a[i] + " a[" + j + "]:" + a[j]);
var aux = a[i];
a[i] = a[j];
a[j] = aux;
}
var value = a[p];
@enriclluelles
enriclluelles / Dockerfile
Created December 4, 2015 00:27
docker build -t compile_swift . && docker run --rm -ti -v $PWD:/app compile_swift
FROM ubuntu:trusty
RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get -y install git cmake ninja-build clang uuid-dev libicu-dev icu-devtools libbsd-dev libedit-dev libxml2-dev libsqlite3-dev swig libpython-dev libncurses5-dev pkg-config
RUN sudo apt-get -y install clang-3.6
RUN sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-3.6 100
RUN sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-3.6 100
ADD build.sh /
(ns diamond.core
(:require [clojure.string :refer [join]]))
(defn char-range [start end]
(map char (range (int start) (inc (int end)))))
(defn steps
[c]
(map str (char-range \A c)))
@enriclluelles
enriclluelles / happy.clj
Last active August 29, 2015 14:15
Happy numbers kata
(require ['clojure.set])
(def happy-numbers (set [1, 7, 10, 13, 19, 23, 28, 31, 32, 44, 49, 68, 70, 79, 82, 86, 91, 94, 97, 100]))
(def not-happy-numbers (clojure.set/difference (set (range 1 100)) happy-numbers))
(defn decompose-in-digits [n]
(map #(Character/digit % 10) (str n)))
(def square #(*' % %))
(defn- happy? [n visited]
@enriclluelles
enriclluelles / gist:12927db9d03bee833520
Created December 18, 2014 17:59
Efficient way of getting a HMACSHA256 payload out of a string and a secret in clojure
(defn hmacSHA256
(memoize (fn [payload secret]
(let [mac (Mac/getInstance "HMACSHA256")
secretKey (SecretKeySpec. (.getBytes secret) (.getAlgorithm mac))
byteResult (-> (doto mac
(.init secretKey))
(.doFinal (.getBytes payload)))
stringResult (->> byteResult
(map #(format "%x" %))
(apply str))]
@enriclluelles
enriclluelles / ext.vim
Last active August 29, 2015 14:11 — forked from sjl/ext.vim
" run command
" no stdin
" output displayed in "Press enter to continue" style
" current buffer untouched
:!uptime
" run command
" pipe range of text to command on stdin
" output replaces the range in the current buffer
:RANGE!grep foo
@enriclluelles
enriclluelles / vg-digitalocean.patch
Last active August 29, 2015 14:06
patch vagrant digitalocean so it sends user_data
From c89f4d9c261fd005258ac551f23dddc835ac719b Mon Sep 17 00:00:00 2001
From: Enric Lluelles <[email protected]>
Date: Sat, 6 Sep 2014 02:06:02 +0200
Subject: [PATCH] Add user data as a provider param
---
lib/vagrant-digitalocean/actions/create.rb | 3 ++-
lib/vagrant-digitalocean/config.rb | 3 +++
2 files changed, 5 insertions(+), 1 deletion(-)