Skip to content

Instantly share code, notes, and snippets.

View CTimmerman's full-sized avatar

Cees Timmerman CTimmerman

View GitHub Profile
@CTimmerman
CTimmerman / file_downloader.py
Last active September 8, 2024 08:40
Resume HTTP download proof of concept (POC) / minimum viable product (MVP). Let unstable internet be no problem working with pip on the road, please.
"""Download with automatic resume.
2018-06-28 v1.0 by Cees Timmerman
2018-07-09 v1.1 Added If-Unmodified-Since header for consistency."""
import os, shutil, sys, time
import requests # python -m pip install requests
def download_file(url, local_filename=None):
if not local_filename:
local_filename = url.split('/')[-1]
@brizandrew
brizandrew / server.py
Last active December 19, 2023 10:16
Simple Flask Webhook Example
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from flask import Flask, request
from urllib import unquote_plus
import json
import re
app = Flask(__name__)
@CTimmerman
CTimmerman / SICP_Scheme_sucks.py
Created September 13, 2017 12:06
Proving that simple for loops are faster for both man and machine.
""" SICP section 2.2.3, page 160.
We can rearrange the pieces and use them in computing the product of the squares of the odd integers in a sequence:
(define (product-of-squares-of-odd-elements sequence) (accumulate * 1 (map square (filter odd? sequence))))
(product-of-squares-of-odd-elements (list 1 2 3 4 5))
225
2017-09-13 v1.0 Translated & benchmarked by Cees Timmerman
"""
from __future__ import print_function # For Python 2.
@deeplook
deeplook / benchmark_fib.sh
Last active May 28, 2019 19:43
Benchmark using Fibonacci numbers with Python, Cython and PyPy.
#!/usr/bin/env bash
echo "Benchmark for Fibonacci numbers with Python3, Cython and PyPy"
echo '
def fib(n):
"Return the n-th Fibonacci number."
i = 0
a, b = 0, 1
if n < 2:
@CTimmerman
CTimmerman / MacOS_sucks.md
Last active January 3, 2024 13:23
MacOS sucks! Making MacOS less painful to use...

Fix horizontal scrolling in Chrome: defaults write com.google.Chrome AppleEnableSwipeNavigateWithScrolls -bool FALSE and restart Chrome. Fix autoscroll with AutoScroll.

  • Minimized windows don't even appear in Chrome's autocomplete!

Disable MacOS widget popover gesture via System Settings, "trackpad gestures", More Gestures, Notification Centre off.

Windows shortcut equivalents:

  • Alt+Enter or F11 = Cmd+Ctrl+F or Globe+F
  • Alt+Tab = Cmd+Tab (Switch app.) or Cmd+` (Switch app window.) No minimized windows. Witch is a bit slow but can cycle windows with Opt+Tab like Windows does, including the browser window you minimized to get to the one behind it, albeit without thumbnails. AltTab is better, also because it doesn't raise all w
@CTimmerman
CTimmerman / simple_git_workflow.md
Last active May 15, 2024 17:00
Simple git workflow
  1. Install Git distributed version control software.
  2. Set up your default credentials (or display without a value to set):
$ git config --global user.name "John Doe"
$ git config --global user.email [email protected]

or if he's a GitHub user, so you see his icon: [email protected]

For example on MacOS:

@fgilio
fgilio / axios-catch-error.js
Last active February 27, 2025 05:50
Catch request errors with Axios
/*
* Handling Errors using async/await
* Has to be used inside an async function
*/
try {
const response = await axios.get('https://your.site/api/v1/bla/ble/bli');
// Success 🎉
console.log(response);
} catch (error) {
// Error 😨
@CTimmerman
CTimmerman / Tech prefs.md
Last active April 24, 2025 09:07
Technology preferences / tech prefs.

My Technology Preferences

For those who don't bother to remember.

Hardware

Personal Computer

A laptop/notebook with 16+ GB RAM, Nvidia GPU for stability (hardware manufacturers seem notoriously bad at software, but Nvidia is relatively good if you ignore the Experience app that demands your data, and training AI needs 50 GB VRAM nowadays but 80 GB is 10x the price of 24 GB), Linux and Wine and/or Windows 10 > expensive, hard-to-customize MacBook with MacOS (needs Spectacle and HyperSwitch to almost be as good as Windows 10), flimsy adapter wire and too many proprietary connectors. Preferably a 14+" matte Full HD (UHD is only useful at 23+" or equivalent in VR) Super AMOLED (except that [burns in](https://www.androidpit.com/h

@CTimmerman
CTimmerman / bookmarklets.js
Last active April 24, 2025 15:34
Bookmarklets / Favelets - Drag to bookmarks bar and rename, then click on page to affect.
// Remove body handlers for WYSIWYG copy/drag for example from this site. Does break this textinput.
javascript:(()=>{let e = document.body; e.parentNode.replaceChild(e.cloneNode(true), e)})()
// Speed up / slow down HTML5 videos! Just set as URLs of bookmark bar items:
javascript:(function(){v = []; for(x of document.querySelectorAll("audio, video")) v.push(x); try{v.push(window.frames[0].document.querySelector("audio, video"))}catch(ex){}; for(i of v) i.playbackRate += .4}())
javascript:(function(){v = []; for(x of document.querySelectorAll("audio, video")) v.push(x); try{v.push(window.frames[0].document.querySelector("audio, video"))}catch(ex){}; for(i of v) i.playbackRate -= .4}())
// Dark mode
javascript:(() => { let ok = false; for (let i = 0; i < 100; ++i) { try { let s = document.styleSheets[i]; s.insertRule("* {background-color: #000b!important; color: #FFF!important; text-shadow: 0 0 1em #fff}", s.cssRules.length); ok = true; break } catch (ex) { console.log("Dark Mode " + ex) } } if (!ok) { let s
@mickeypash
mickeypash / game-of-life.py
Created July 10, 2016 10:20
Conway's Really Simple Game of Life based on ("Stop Writing Classes" PyCon 2012)[https://www.youtube.com/watch?v=o9pEzgHorH0]
import itertools
# Conway's Really Simple Game of Life based on "Stop Writing Classes" PyCon 2012
def neighbors(point):
x,y = point
yield x + 1, y
yield x - 1, y
yield x, y + 1
yield x, y - 1