Skip to content

Instantly share code, notes, and snippets.

@doekman
doekman / README.md
Last active June 12, 2019 02:39
Add support for page overlays to support non-trivial page headers/footers in Flask-WeasyPrint

Paged media CSS doesn't support more complex page header/footer requirements, like tables. A solution to this is to create a separate page with such a header, and merge this into the PDF on the required pages. A proof of concept was written by pikhovkin in this Gist.

Overlay: Represents one HTML page to be overlaid on a PDF document.

  • template_name_or_list: the name of the HTML template, which is resolved with jinja2's get_or_select_template method.
  • fn_include_on_page: a function that takes a 0-based page number, and returns a boolean that indicates if it needs to be included on that page.
  • kwargs: context used to render the overlay. Can also be used to dynamically position content.
@doekman
doekman / human_sort.sh
Last active January 2, 2019 21:55
Command-line program that sorts standard input as a human would expect.
# Rewrite from python ;-)
alias human_sort="sort --version-sort --ignore-case"
@doekman
doekman / pull-all.sh
Created December 19, 2016 20:09
Update all git repositories in direct subdirectories
#!/usr/bin/env bash
find . -maxdepth 1 -mindepth 1 -type d | while read i; do (cd "$i"; if [[ -d ".git" ]]; then echo "Checking $i" && git pull; fi; cd ..); done
@doekman
doekman / iambored.py3
Created July 19, 2016 11:17
Opens one item from secretGeek's best-of-wikipedia listing in your favorite browser.
#!/usr/bin/env python3
# Tested on OS X
from lxml import html
import requests
import random
from subprocess import call
page = requests.get('http://wiki.secretgeek.net/best-of-wikipedia')
on trim(theseCharacters, someText)
if class of someText is text and length of someText > 0 then
-- default values (all whitespace)
if theseCharacters is true then ¬
set theseCharacters to {" ", tab, ASCII character 10, return, ASCII character 0}
repeat until first character of someText is not in theseCharacters
set someText to text 2 thru -1 of someText
end repeat
@doekman
doekman / rand.js
Created February 11, 2016 09:44
Limit a random number to a range of integers
function rand(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
//The following gives the first and last element 50% less chance
//return Math.round(Math.random() * (max - min)) + min;
}
@doekman
doekman / repeat.js
Created January 16, 2016 19:08
repeat one-liner
function repeat(str,num) {
return new Array(num+1).join(str);
}
@doekman
doekman / isLeapYear.js
Last active October 20, 2015 17:51
To refactor, or not to refactor
// Refactor step 7, still don't like it, f*ck it, just use native function
function isLeapYear(year) {
return new Date(year, 2-1, 29).getDate() == 29;
}
@doekman
doekman / PropertyHelper2.cs
Created February 20, 2015 16:08
Changed ObjectToDictionary implementation, for handling arrays. The change is in the file TypeHelper2.cs; The file PropertyHelper2.cs is an internal class, so it was necessary to include it here too.
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Reflection;
namespace System.Web.WebPages
@doekman
doekman / count.ps1
Last active August 29, 2015 14:08 — forked from secretGeek/count.ps1
Get-Content *.md | Measure-Object –Word | % { $count = $_.Words }
hg add
$message = "words:" + $count
$todo = (get-content .\todo.txt | select-string -pattern "[_]").length
$done = (get-content .\todo.txt | select-string -pattern "[x]").length
$message = $message + ", tasks: " + $done + "/" + ($todo + $done) + ""
hg commit -m $message
& .\progress.ps1