Skip to content

Instantly share code, notes, and snippets.

View dlebech's full-sized avatar

David Volquartz Lebech dlebech

View GitHub Profile
@dlebech
dlebech / error.js
Last active December 15, 2015 19:16
Just testing out Error subclassing
'use strict';
class MyError extends Error {}
class MyVerboseError extends Error {
constructor(message) {
super(message);
this.name = this.constructor.name; // ! important
this.message = message;
Error.captureStackTrace(this, this.name);
@dlebech
dlebech / selenium.js
Created December 18, 2015 15:39
Node + Mocha + Selenium
'use strict';
const By = require('selenium-webdriver').By,
until = require('selenium-webdriver').until,
firefox = require('selenium-webdriver/firefox'),
test = require('selenium-webdriver/testing'),
utils = require('../utils'),
server = require('../server');
describe('register', function() {
@dlebech
dlebech / letsencrypt.sh
Created February 25, 2016 09:04
Just so I don't forget, the one-liner to use for generating letsencrypt certs.
# One-liner for creating a certificate on a webserver.
# Install the letsencrypt github repo and then
./letsencrypt-auto certonly --webroot -w /var/www/websitename/or/whatever -d domain.com

This is a copy of a support chat between Intercom and myself. It's referred to from a blog post I wrote here.

David:

Hello there

I wanted to make a report of what I believe to be a security hole in your app.

I recently had a support chat session with a service I use while being logged-in.

@dlebech
dlebech / perl.sh
Created May 4, 2017 10:21
Command-line notes
# Convert a unix timestamp in millisconds in a column of a CSV to a date
cat thefile.csv | perl -MPOSIX -pe 's/(^\d+),/strftime("%F,", localtime($1\/1000))/ge'
@dlebech
dlebech / redis.go
Created May 19, 2016 07:16
Connecting to Redis in Golang
package services
import (
"os"
"time"
log "github.com/Sirupsen/logrus"
"github.com/garyburd/redigo/redis"
)
@dlebech
dlebech / difflibtest.py
Created February 17, 2015 20:37
Python difflib test to see the difference between the different ratios.
#!/bin/env python
import difflib
import random
import string
import time
repetitions = 100000
# Pre-generate strings between 5 and 30 characters in length.
strings = [''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(random.randint(10,30))) for i in range(repetitions*2)]
@dlebech
dlebech / keras_embedding_onehot.py
Last active June 16, 2018 10:30
Minimal Keras examples for various purposes
# Public Domain CC0 license. https://creativecommons.org/publicdomain/zero/1.0/
# Create a Keras embedding layer with an initial one-hot encoding by using identity initializer
import tensorflow as tf
import numpy as np
# Input sequence consisting of four features (e.g. words)
# Let's pretend this is "hello world hello everyone else"
# Where hello is then mapped to 1, world = 0, everyone = 2, else = 3,
a = np.array([[1, 0, 1, 2, 3]])
@dlebech
dlebech / ft_extract.py
Last active June 8, 2019 07:11
Extract photos and names of members of Danish parliament
# Public Domain CC0 license. https://creativecommons.org/publicdomain/zero/1.0/
# Run this file first, e.g.:
# $ scrapy runspider ft_extract.py -o members.json
#
# It will probably stop working if they change their urls for the contact list of course.
# Worked in Spring of 2019
import scrapy
import re
from urllib.parse import urlparse, urlunparse
@dlebech
dlebech / oneliners_matplotlib.py
Last active March 13, 2020 15:29
Matplotlib useful one liners that I always forget
# Matplotlib
# Creating a list of colors (e.g. for a bar chart)
# "Blues" is the colormap. It can be any colormap
# https://matplotlib.org/examples/color/colormaps_reference.html
colors = [matplotlib.colors.to_hex(c) for c in plt.cm.Blues(np.linspace(0, 1, len(some_dataframe.index)))]
# Globally adjusting DPI and figure size
matplotlib.rcParams['figure.dpi'] = 100
matplotlib.rcParams['figure.figsize'] = [6.0, 4.0]