Skip to content

Instantly share code, notes, and snippets.

View promises.js
async function main(url) {
const root = document.getElementById('root');
root.innerHTML = 'Hello world';
setTimeout(() => {
root.innerHTML = 'Something else';
}, 2000);
root.addEventListener('click', () => {
root.innerHTML = 'You clicked root!';
root.innerHTML = 'Hej Class!';
@mattiaslundberg
mattiaslundberg / promises.js
Created August 4, 2019 09:52
FooCoding s01 Promises
View promises.js
// Create new promise
const p = new Promise((resolve, reject) => {
reject(new Error('some error'));
//resolve('Some data');
});
// Then/catch
p.then(result => console.log(result)).catch(error => console.error(error));
// Async
@mattiaslundberg
mattiaslundberg / Ansible Let's Encrypt Nginx setup
Last active March 9, 2023 15:47
Let's Encrypt Nginx setup with Ansible
View Ansible Let's Encrypt Nginx setup
Ansible playbook to setup HTTPS using Let's encrypt on nginx.
The Ansible playbook installs everything needed to serve static files from a nginx server over HTTPS.
The server pass A rating on [SSL Labs](https://www.ssllabs.com/).
To use:
1. Install [Ansible](https://www.ansible.com/)
2. Setup an Ubuntu 16.04 server accessible over ssh
3. Create `/etc/ansible/hosts` according to template below and change example.com to your domain
4. Copy the rest of the files to an empty directory (`playbook.yml` in the root of that folder and the rest in the `templates` subfolder)
@mattiaslundberg
mattiaslundberg / profile.py
Last active July 20, 2018 22:54
Inline profiling in Python (2.7)
View profile.py
# https://docs.python.org/2/library/profile.html
import cProfile
pr = cProfile.Profile()
pr.enable()
try:
pass # Code to profile
finally:
pr.disable()
pr.dump_stats('filename')
@mattiaslundberg
mattiaslundberg / pylgtv.py
Created May 30, 2014 13:53
Control LG televisions from python
View pylgtv.py
import serial
import re
class LGTV(object):
""" Interface for serial control of LG Televisions """
def __init__(self, port='/dev/ttyUSB0'):
super(LGTV, self).__init__()
self.port = port
@mattiaslundberg
mattiaslundberg / inlineeditbox.html
Last active August 29, 2015 14:01
Update the regExp of a dojo validation textbox
View inlineeditbox.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Test validation</title>
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.9.2/dojo/resources/dojo.css">
<link rel="stylesheet" type="text/css" href="https://ajax.googleapis.com/ajax/libs/dojo/1.9.2/dijit/themes/claro/claro.css">
</head>
<body class="claro">
<h1 id="headline">Change the text to something without spaces:</h1>
@mattiaslundberg
mattiaslundberg / voronoi.py
Created May 7, 2014 17:18
Voronoi diagram generation with Fortune's algorithm in Python2 and Tk
View voronoi.py
################################################################################
# VORONOI DIAGRAM GENERATION #
# Mattias Lundberg #
# #
# Run with Python 2.7 and tkinter toolkit #
# #
################################################################################
from Tkinter import *
import math, sys, random, tkFileDialog, time
@mattiaslundberg
mattiaslundberg / arch-linux-install
Last active March 22, 2023 16:02
Minimal instructions for installing arch linux on an UEFI system with full system encryption using dm-crypt and luks
View arch-linux-install
# Install ARCH Linux with encrypted file-system and UEFI
# The official installation guide (https://wiki.archlinux.org/index.php/Installation_Guide) contains a more verbose description.
# Download the archiso image from https://www.archlinux.org/
# Copy to a usb-drive
dd if=archlinux.img of=/dev/sdX bs=16M && sync # on linux
# Boot from the usb. If the usb fails to boot, make sure that secure boot is disabled in the BIOS configuration.
# Set swedish keymap
View iptablessetup
#!/bin/bash
IPTABLES="/sbin/iptables"
IP6TABLES="/sbin/ip6tables"
# Helper function for confirming allow rules
confirm() {
while true; do
read -p "Allow $1? " yn
case $yn in
@mattiaslundberg
mattiaslundberg / latexpdf
Last active December 19, 2015 00:39
Autobuild latex files.
View latexpdf
#!/usr/bin/env bash
########################
# Copyright (c) 2013, Mattias Lundberg
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
#