Skip to content

Instantly share code, notes, and snippets.

View willwillems's full-sized avatar
🌱
Working remotely

Will Willems willwillems

🌱
Working remotely
View GitHub Profile
@willwillems
willwillems / scraper.py
Last active February 18, 2017 11:27
Simple Python 3.5.2 Marktplaats scraping example with Beautiful Soup 4
import requests
import urllib.parse
import numpy as np
import matplotlib.pyplot as plt
from bs4 import BeautifulSoup
def crawlmp( base_url, parameters, add_to_url = '' ):
""" Parameters dictionairy can contain:
query[str],
categoryId[int],
@willwillems
willwillems / wildcard_SSL_dns_callange.md
Created April 9, 2018 09:06
Switch to wildcard SSL cert with certbot

If you want to switch from using a regulair certificate/certificates to using Let's Encrypt's new wildcard cert there are some things you still neeed to do, here is a simple command that should suffice:

sudo certbot certonly --cert-name YOURCERTNAME.com -d *.DOMAIN.com,DOMAIN.com --server https://acme-v02.api.letsencrypt.org/directory --manual --preferred-challenges=dns

Certbot will walk you trough the verfication using DNS which currently is the only option with wildcard support, you'll need to add two TXT record for verification.

Good luck!

@willwillems
willwillems / CompoundInterestCalculator.js
Last active July 2, 2018 17:56
Calculates total savings due to compund interest based on a yearly rate and a monthly deposit.
// Calculates total savings as result of a monthly deposit.
// vars
var monthlySaving = 500; // monthly amount you deposit in your savings account/index fund
var initialSavings = 0; // initial capital you start with
var yearlyInterest = 1.05 // in this case %5
var years = 15; // amount of years to calculate for
var goal = 0 // financial goal, can leave at 0
// computed
@willwillems
willwillems / upload.js
Created January 28, 2019 09:55
Upload email templates to Sparkpost
require('dotenv').config()
const fs = require('fs')
const path = require('path')
const SparkPost = require('sparkpost')
const templateFolder = './templates/html/'
const sparkpostApiKey = process.env.SPARKPOST_API_KEY
const client = new SparkPost(sparkpostApiKey)
@willwillems
willwillems / AppCompass.vue
Created May 3, 2019 09:51
A compass indicator component for Vue.js
<template>
<div class="compass">
<!-- Arrow -->
<svg class="compass__arrow" :style="`transform: rotate(${degrees}deg);`" width="37px" height="36px" viewBox="0 0 37 36" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="spot-search-copy-10" transform="translate(-236.000000, -796.000000)">
<g id="Group" transform="translate(236.000000, 796.000000)">
<rect id="Rectangle" opacity="0" x="0.5" y="0" width="36" height="36"></rect>
<polygon id="Rectangle" fill="#FFFFFF" points="14 18 18.5 7 23 18 18.5292306 29"></polygon>
<polygon id="Rectangle" fill="#FF0000" transform="translate(18.500000, 12.500000) scale(1, -1) translate(-18.500000, -12.500000) " points="14 7 23 7 18.5292306 18"></polygon>
@willwillems
willwillems / download-zip.js
Created August 12, 2019 19:07
Get .zip file with Node, unzip it and save it to disk by piping the response body into unzipper
const unzipper = require('unzipper');
const fetch = require('node-fetch')
// get data
fetch('https://example.org/my-archive.zip')
.then(resp => {
return new Promise((res, rej) => {
resp.body
.pipe(unzipper.Extract({ path: '/tmp/my-archive' }))
.on('error', rej)
@willwillems
willwillems / indent.js
Last active April 12, 2020 11:12
Indent browser CSS with a simple JS function
const indent = code => code
.replace(/{\s+/, '{\n ')
.replace(/(?<=;)\s+/gm, '\n ')
.replace(/(?<=;)\s+}/, '\n} ')
@willwillems
willwillems / fullscreen-activate.js
Last active May 3, 2020 10:33
Put Roam Research in fullscreen by clicking anywhere.
((b) => { b.style.backgroundColor = 'white'; b.addEventListener('click', () => b.requestFullscreen(), {once: true})})(document.body)
@willwillems
willwillems / AppStartRating.vue
Created November 22, 2020 14:11
Vue Component for 5 star rating
<template>
<div class="product-rating" :class="{'product-rating--invalid': ratingIsNan}">
<div class="product-rating__value-cutoff" :style="`width: ${cutoffWidth}%;`">
<img class="product-rating__star" :class="{'product-rating__star--small': isSmall}" src="/icon/star.svg" />
<img class="product-rating__star" :class="{'product-rating__star--small': isSmall}" src="/icon/star.svg" />
<img class="product-rating__star" :class="{'product-rating__star--small': isSmall}" src="/icon/star.svg" />
<img class="product-rating__star" :class="{'product-rating__star--small': isSmall}" src="/icon/star.svg" />
<img class="product-rating__star" :class="{'product-rating__star--small': isSmall}" src="/icon/star.svg" />
</div>
</div>
@willwillems
willwillems / getMatchingCSSRulesForEl.js
Created January 10, 2021 13:55
Get matching CSS rules for a DOM element using the new CSSOM stylesheet implementation
function getMatchingCSSRulesForEl (el) {
return [...document.styleSheets]
.filter(ss => { try { return ss.cssRules; } catch (e) { return false } })
.flatMap(e => [...e.cssRules].filter(r => el.matches(r.selectorText)))
}