Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
#
# Toggle the state (STOPPED/RUNNING) of a process, clicking to its window.
set -e
debug() { echo "$@" 2>&1; }
die() { local MESSAGE=$1
debug "Error: $MESSAGE"
exit 1
@tokland
tokland / dhondt.py
Last active December 18, 2015 11:50
Pure functional implementation of D'Hondt method
# Pure functional implementation of D'Hondt method
from itertools import islice, count
from collections import Counter
from heapq import merge
def percentage(numerator, denominator):
return 100.0 * numerator / denominator
def take(n, it):
@tokland
tokland / Annotations.java
Last active January 29, 2016 11:03
Basic Runtime Annotation
import java.lang.annotation.Target;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.ElementType;
import java.lang.reflect.Method;
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@interface MyAnnotation {
String name() default "";
@tokland
tokland / spanish_dni_nif_validator.js
Last active March 9, 2016 11:01
DNI/NIF validators (Spain ID documents)
/* Return sum of numbers in array xs */
function sum(xs) {
return xs.reduce(function(a, b) { return a + b }, 0);
}
/* Return true if string s is a valid DNI */
function validateDNI(s) {
var control_letters = 'TRWAGMYFPDXBNJZSQVHLCKE';
var regexp = /^[\dKLMXYZ]\d{7}[A-Z]$/;
import sys
import signal
from PyQt4 import QtCore, QtGui, QtWebKit
from PyQt4.QtNetwork import QNetworkAccessManager, QNetworkCookieJar, QNetworkCookie
class ExtendedNetworkCookieJar(QNetworkCookieJar):
def mozillaCookies(self):
"""
Return all cookies in Mozilla text format
require 'capybara'
# $ xvfb-run rspec -f documentation chrome-extension_spec.rb
#
# ./myext -- Directory containing the unpacked extension
class ChromeBrowser
include Capybara::DSL
def initialize(chrome_flags = {})
// ==UserScript==
// @name DeezerCLI
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Control Deezer web player from the console
// @author pyarnau@gmail.com
// @match http://www.deezer.com/*
// @grant none
// ==/UserScript==
@tokland
tokland / google-timeline-download.sh
Last active May 14, 2024 16:47
Get KML of Google Maps Timeline for a date range
#!/bin/bash
set -e -u -o pipefail
# Usage: Export a cookies.txt file from a browser logged-in in timeline.google.com with some
# add-on/extension (i.e. Export cookies, Get cookies.txt). Now run the script for the
# desired period:
#
# $ bash google-timeline-download.sh cookies.txt 2022-01-01 2022-02-20 out.kml
#
# Dependencies: curl, perl-xml-twig.
<html xmlns="http://www.w3.org/1999/xhtml" lang="es" xml:lang="es">
<head>
<title>Testing DataTable/ColOrder with async call</title>
<script src="http://code.jquery.com/jquery-1.12.4.js"></script>
<script src="http://nightly.datatables.net/js/jquery.dataTables.min.js"></script>
<script src="http://nightly.datatables.net/colreorder/js/dataTables.colReorder.js"></script>
<script>
$(document).ready(function() {
var table = $('#example').DataTable({
@tokland
tokland / functional_virtual_dom_simple_demo.html
Last active March 19, 2017 21:13
Simple demo using immutable states with virtual-dom
<html xmlns="http://www.w3.org/1999/xhtml" lang="es" xml:lang="es">
<head>
<title>Simple functional app using VirtualDom</title>
<script src="http://wzrd.in/standalone/virtual-dom@latest"></script>
<script src="simple_virtual_dom.js"></script>
<script src="incrementor.js"></script>
</head>
<body>
<div id="incrementor">