Skip to content

Instantly share code, notes, and snippets.

@le717
le717 / hosts.sql
Last active November 26, 2023 20:46
#vss365 Wrapped 2023
SET @year = 2023;
-- Get all hosts
SELECT
h.handle AS `Host`,
hd.date AS `Hosting period start date`
FROM hosts h
INNER JOIN host_dates hd
ON h._id = hd.host_id
WHERE
@le717
le717 / renderer.py
Last active November 17, 2023 21:41
"""Transparent app/non-app context Jinja rendering setup.
Use this module whenever you need to render Jinja templates outside
the app context or in code that is shared between app/non-app contexts,
such as in Celery tasks.
If available, the app context renderer will be used. Otherwise, a mostly
identical Jinja render environment will be created, with the caveat that
it may not be as efficient and will not support all Flask-provided
convenience rendering features.
SET @year = 2022;
-- Get all hosts
SELECT
w.handle AS `Host`,
wd.date AS `Hosting period start date`
FROM writers w
INNER JOIN writer_dates wd
ON w.uid = wd.uid
WHERE
@le717
le717 / battleship-v1-2.js
Created August 28, 2014 18:51
v1.2 of Elisabeth Robson ( https://github.com/bethrobson )'s Battleship game from her book Head First JavaScript program, which I am using as the textbook at college. I call it v1.2 as I made it slightly more advanced than it should be at the end of Chapter 2. 😃
/* jshint -W097 */
/* global prompt, alert */
"use strict";
var guess,
loc1 = Math.floor(Math.random() * 5),
loc2 = loc1 + 1,
loc3 = loc1 + 2,
hits = 0,
isSunk = false,
guesses = [];
<?php
function sqlURL($sql_input) {
$res = parse_url($sql_input);
if(!isset($res['scheme'])) {
$sql_input = "http://".$sql_input;
}
$sql_input = str_replace("'","\'",stripslashes($sql_input));
<?php
function makeSQLsafe($sql_input) {
$sql_input = str_replace("'","\\'",stripslashes($sql_input));
$sql_input = str_replace('"','\\"',$sql_input);
$sql_input = str_replace(';','\\;',$sql_input);
//$sql_input = str_replace('%','\\%',$sql_input);
//$sql_input = str_replace('_','\\_',$sql_input);
$sql_input = str_replace("&","&amp\\;",$sql_input);
$sql_input = str_replace("<","&lt\\;",$sql_input);
$sql_input = str_replace(">","&gt\\;",$sql_input);
@le717
le717 / extract-android-memos.py
Created November 25, 2021 14:15
A small python script to extract memo text from a Samsung Galaxy S7 .memo file (aka a .zip archive)
from html import unescape
from pathlib import Path
from xml.etree import ElementTree
all_memos = Path().rglob("memo_content.xml")
output_dir = Path("output")
output_dir.mkdir(exist_ok=True)
for memo in all_memos:
@le717
le717 / reset-normal.ps1
Created September 16, 2021 12:12
Powershell script to find and delete MS Word's Normal.dotm template file
# Get a link to the root AppData folder
$appdata = $(Join-Path -Path $(Resolve-Path ~) -ChildPath "AppData")
Write-Host "Searching for Normal.dotm in $($appdata)"
Write-Host "This may take some time..."
# Search for the Normal.dotm file
$results = Get-ChildItem -Path $appdata -Filter Normal.dotm -Recurse -ErrorAction SilentlyContinue -Force
# It found the file
if ($results -ne $null) {
export function find_parent(element, selector) {
// The desired element was not found on the page
if (element === null) {
return null;
}
// We found the desired element
if (element.matches(selector)) {
return element;
@current_app.before_request
def detect_ie_browser():
"""Redirect all IE visitors to a special page
informing them to get a web browser.
"""
# For this to work, the following conditions must be met:
# 1. The visitor is using IE (doesn't matter what version)
# 2. We must not be currently requesting a static file
# (we still need page styles/resources to load)
# 3. We don't need to be directly requesting the special page