Skip to content

Instantly share code, notes, and snippets.

@Glench
Glench / watch_notebooks.py
Created March 23, 2013 15:46
a python script that watches the current directory for changes to ipython notebooks, compiles them to html, and uploads them via scp to a server. an experiment in real-time coding for teaching python to new programmers
import time
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
import envoy
import os
import datetime
class NotebookConverterHandler(FileSystemEventHandler):
def on_modified(self, event):
if event.src_path.endswith('.ipynb'):
// ==UserScript==
// @name Show Image Alt Text
// @namespace http://tampermonkey.net/
// @version 0.1
// @description https://www.reddit.com/r/chrome_extensions/comments/qhpcw4/looking_for_an_extension_that_will_always_show/
// @author You
// @match http*://*
// @grant none
// ==/UserScript==
// ==UserScript==
// @name Filter Youtube Homepage by Age
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Remove Youtube videos from homepage that are over x years old
// @author @Glench
// @match https://www.youtube.com/
// @icon https://www.google.com/s2/favicons?domain=youtube.com
// @grant none
// ==/UserScript==
function is_loading() {
return document.querySelector('#UpdateProgress3').getAttribute('aria-hidden') == 'false';
}
function wait_till_load_done() {
setTimeout(function() {
if (!is_loading()) {
scrape_table()
} else {
wait_till_load_done();
@Glench
Glench / python-async-callback.py
Last active August 2, 2021 10:34
An example of how to vary a parameter for an async callback function in python. Hint: don't use lambda functions in loops!
"""
We want to run a function asychronously and run a
callback function with multiple parameters when it
returns!
In this example, we are pretending we're analyzing
the names and ages of some people. We want to print
out:
jack 0
@Glench
Glench / tv_tropes_common_tropes.py
Last active January 8, 2021 08:32
A command-line script to find the common tropes of two or more media items. To use, you need to install the python libraries 'pattern' and 'pyquery'. Then use like this, passing in media names or links to tv tropes pages: > python tv_tropes_common_tropes.py 'My Little Pony Friendship is Magic' 'Hamlet'
#!/usr/bin/python
# a script to get all the common tropes for media from tv tropes
# usage:
# python tv_tropes_matcher.py name1 name2 [name3...nameN]
# please put names with spaces or special characters in quotes
# you can also pass in the urls if it won't automatch by name.
# pip install pattern
# pip install pyquery
@Glench
Glench / example.svelte
Last active December 19, 2020 19:02
An idea for how SvelteKit could bridge the front-end/back-end gap more elegantly
<script context="backend">
// /routes/index.svelte
import db from '/db';
export async function get(req, abort, redirect) {
const user = await db.User.findOne({where: {id: req.query.user_id}});
return {user}
}
</script>
@Glench
Glench / scratch_fullscreen_cover.js
Last active April 14, 2020 17:36
Set Scratch UI to black
{
// sets everything but stage to black on full-screened https://scratch.mit.edu/projects/editor/
const stage = document.querySelector('[class^="stage_stage-bottom-wrapper"]')
const rect = stage.getBoundingClientRect();
const pageHeight = document.documentElement.scrollHeight;
var leftCover = document.createElement('div');
@Glench
Glench / body_reminder.py
Created April 26, 2019 19:50
A meditation reminder app when I'm using the computer
# This Python file uses the following encoding: utf-8
import subprocess
import time
breathing_time = 30 # seconds
interval_between_breathing = 25 * 60 # seconds
applescript = """
display dialog "Breathe and make a home of your body" ¬
import play
@play.when_any_key_pressed
def do(key):
text = play.new_text(':(', y=play.screen.bottom)
text.start_physics(x_speed=play.random_number(-20,20), y_speed=100, bounciness=.3)
play.start_program()