Skip to content

Instantly share code, notes, and snippets.

View CTimmerman's full-sized avatar

Cees Timmerman CTimmerman

View GitHub Profile
@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 johndoe@example.com

or if he's a GitHub user, so you see his icon: johndoe@users.noreply.github.com

For example on MacOS:

@fgilio
fgilio / axios-catch-error.js
Last active April 11, 2024 19:02
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 May 23, 2024 09:46
Technology preferences / tech prefs.

My Technology Preferences

Hardware

A PC 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) [display](http

@CTimmerman
CTimmerman / bookmarklets.js
Last active June 8, 2023 21:32
Bookmarklets / Favelets - Drag to bookmarks bar and rename, then click on page to affect.
// 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}())
// Highlight new Facebook notifications.
javascript:(function(){var s = document.createElement('style'); s.appendChild(document.createTextNode(".jewelItemNew ._33e{background-color:lightgreen!important;}")); document.head.appendChild(s)}())
// Show videos from messy framework HTML, can't show toolbar in popup due to Chrome bug 82522.
javascript:(function(){var w=window.open();var d=w.document;d.title='Videos';d.body.style.backgroundColor='0';for(var v of document.getElementsByTagName('video')){v.style='';v.controls
@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
@gunjanpatel
gunjanpatel / revert-a-commit.md
Last active May 7, 2024 22:00
Git HowTo: revert a commit already pushed to a remote repository

Revert the full commit

Sometimes you may want to undo a whole commit with all changes. Instead of going through all the changes manually, you can simply tell git to revert a commit, which does not even have to be the last one. Reverting a commit means to create a new commit that undoes all changes that were made in the bad commit. Just like above, the bad commit remains there, but it no longer affects the the current master and any future commits on top of it.

git revert {commit_id}

About History Rewriting

Delete the last commit

Deleting the last commit is the easiest case. Let's say we have a remote origin with branch master that currently points to commit dd61ab32. We want to remove the top commit. Translated to git terminology, we want to force the master branch of the origin remote repository to the parent of dd61ab32: