Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python3
import re
from contextlib import closing
from epub import create_epub, DEFAULT_STYLESHEET
import requests
import requests_cache
from bs4 import BeautifulSoup
from smartypants import smartypants
@glombard
glombard / reference-markdown-metadata-from-jinja-template.py
Last active March 28, 2025 20:52
How to use Markdown as a filter in a Jinja2 template, and then extract the Markdown Meta property directly from the template. Assuming you want to use the Meta-data value before rendering the converted Markdown content (e.g. in the html head), the trick is to render the markdown first, save it to a variable (html_content in this example) using a…
from pprint import pprint
import jinja2
import markdown
HTML_TEMPLATE = """{% macro get_html() %}
{{ content | markdown }}
{% endmacro %}
{% set html_content = get_html() %}
Title from Markdown meta-data: {{ get_title() }}
@scottyob
scottyob / hid-via-bluetooth.cpp
Last active September 8, 2022 09:02
Arduino Leonardo HID keyboard and mouse via Seeeduino Bluetooth Module.
/*
This code will be used as a demo to controll the mouse and keyboard from an Arduino Leonardo.
It shows an example of recieving commands from a remote Bluetooth endpoint (be it computer, mobile phone, etc) and using those commands to control
the mouse and keyboard of a locally connected USB target.
Any character that gets recieved will be typed into the keyboard, unless that character is a '#' which we will use to toggle between mouse and keyboard modes
Once in mouse mode, the following characters will be used as commands:
'u': Move the mouse up
'd': Move the mouse down
@mortennobel
mortennobel / Event.h
Last active July 3, 2018 14:46
C++11 Observer Version 2
//
// Event.h
//
// Created by Morten Nobel-Jørgensen on 8/18/13.
// Copyright (c) 2013 morten. All rights reserved.
// Open Source under New BSD License (http://opensource.org/licenses/BSD-3-Clause)
#pragma once
#include <iostream>
@drhelius
drhelius / Game Boy Boot ROM Disassembly
Last active March 13, 2025 14:12
Game Boy Boot ROM Disassembly
LD SP,$fffe ; $0000 Setup Stack
XOR A ; $0003 Zero the memory from $8000-$9FFF (VRAM)
LD HL,$9fff ; $0004
Addr_0007:
LD (HL-),A ; $0007
BIT 7,H ; $0008
JR NZ, Addr_0007 ; $000a
LD HL,$ff26 ; $000c Setup Audio
@roxlu
roxlu / Oils.cpp
Created July 10, 2013 14:36
Attribute-less rendering with openGL - you're not allowed to draw with the default VertexArray so you need to create one.
#include <assert.h>
#include <roxlu/core/Log.h>
#include "Oils.h"
Oils::Oils()
:win_w(0)
,win_h(0)
,br_prog(0)
,br_vert(0)
,br_frag(0)
from fabric.api import local
import pip
def freeze ():
local("pip freeze > requirements.txt")
local("git add requirements.txt")
local("git commit -v")
def upgrade ():
for dist in pip.get_installed_distributions():
@zach-klippenstein
zach-klippenstein / ChangePassword.java
Last active June 23, 2024 19:01
The keystore password on Java keystore files is utterly pointless. You can reset it without knowing it, as shown by this code. Note that private keys are still secure, as far as I know. The JKS implementation is copyright Casey Marshall ([email protected]), and the original source is available at http://metastatic.org/source/JKS.java. I've in…
import java.util.*;
import java.io.*;
import java.security.*;
public class ChangePassword
{
private final static JKS j = new JKS();
public static void main(String[] args) throws Exception
{
@geertj
geertj / winsocketpair.py
Last active October 3, 2024 16:11
Emulates the UNIX socketpair() system call on Windows. This function uses a trick with non-blocking sockets to prevent the need for a thread. A socketpair can be used as a full-duplex, select()able pipe on Windows.
def socketpair(family=socket.AF_INET, type=socket.SOCK_STREAM, proto=0):
"""Emulate the Unix socketpair() function on Windows."""
# We create a connected TCP socket. Note the trick with setblocking(0)
# that prevents us from having to create a thread.
lsock = socket.socket(family, type, proto)
lsock.bind(('localhost', 0))
lsock.listen(1)
addr, port = lsock.getsockname()
csock = socket.socket(family, type, proto)
csock.setblocking(0)