Skip to content

Instantly share code, notes, and snippets.

View njamescouk's full-sized avatar

nick james njamescouk

View GitHub Profile
@njamescouk
njamescouk / chkSql.bat
Last active March 20, 2017 15:04
scrape SELECTs from markdown and run them against sqlite database reporting errors
@echo off
goto main
This is a quick hack, should be easy to port
to linux but I'm still looking for a usable
systemd free distro so haven't done it
we rely on
1. SELECT being upper case
@njamescouk
njamescouk / dbeditExample.tcl
Last active January 29, 2018 12:21
using tcl, sqlite and dbedit
package require Tk
package require sqlite3
source "dbedit.tcl"
# open example.db or create if absent
# dbhandle is how we access the db
set dbName ":memory:"
sqlite3 dbhandle $dbName
# set up sql to create & populate table
@njamescouk
njamescouk / minimalGui.tcl
Last active February 10, 2018 23:26
minimal tcl/tk gui
package require Tk
proc minmal {w} {
global minimalStatus
set curFile [fileDialog $w]
if {$curFile eq "" } {
set minimalStatus {no file specified}
return
}
@njamescouk
njamescouk / genTemplates.bat
Created February 22, 2018 20:47
generate default templates for pandoc
@echo off
goto main
My installation of pandoc didn't have the advertised templates or the
advertised directory they were meant to be in, which is a nuisance if
you need to modify them. This batch file should do the job.
:main
pandoc -v | grep "fault user" | sed "s/^[^:]*: *\(.*\)/\1/" > genT_tmpfile
set /p PANDOC_USER_DIR=<genT_tmpfile
@njamescouk
njamescouk / substr.sql
Created February 24, 2018 16:55
elucidating sqlite's substr() function
SELECT '/*
results
initial string "abcdefghijklmnopqrst" of length ' || length('abcdefghijklmnopqrst'); -- 20
SELECT '3 letters starting with 6th =' || substr('abcdefghijklmnopqrst', 6, 3); -- fgh
SELECT '
2 ways of selecting 3 letters starting 6th from the end';
SELECT substr('abcdefghijklmnopqrst', -6, 3); -- opq
@njamescouk
njamescouk / angle.cpp
Last active April 11, 2018 15:49
get angle of position vector wrt to initial line.
/*
angle.cpp
compute angle given sine and cosine
*/
#include <cmath>
#include <cstdio>
#include <cassert>
@njamescouk
njamescouk / chkSql.sh
Created November 25, 2018 20:59
scrape SELECTs from markdown and run them against sqlite database reporting errors - bash version
# This is a quick hack
#
# we rely on
# 1. SELECT being upper case
# 2. SELECT prefixed with at least 4 spaces, or ~~~\nSELECT,
# to induce <code> tag
# 3. no embedded semi colons in, for eg comments
# 4. semi colon not on the same line as it's SELECT
#
# error reporting leaves *a lot* to be desired
@njamescouk
njamescouk / createRoundTripDb.sql
Last active May 12, 2019 12:03
simple minded load db - display - add row - save html + js to demo sql.js
-- do
-- sqlite3 roundTrip.db < createRoundTripDb.sql
-- then open roundTrip.db from sqlJsRoundTrip.html
-- you may need to press the load db button, or you may not
-- sql.js is available at https://github.com/kripken/sql.js/
PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE t
(
f1 TEXT
@njamescouk
njamescouk / fractions.latex
Created September 15, 2019 11:13
produce fractions when using pandoc to go from latex to html
\documentclass{article}
\begin{document}
\begin{tabular}[]{ r r r r r r r r }
to the power & $^{^-1}$ & $^{^-2}$ & $^{^-3}$ & $^{^-4}$ & $^{^-5}$ & $^{^-6}$ & \ldots{}\\[.5em]
2 & $\frac{1}{2}$ & $\frac{1}{4}$ & $\frac{1}{8}$ & $\frac{1}{16}$ & $\frac{1}{32}$ & $\frac{1}{64}$ & \ldots{}\\[1em]
3 & $\frac{1}{3}$ & $\frac{1}{9}$ & $\frac{1}{27}$ & $\frac{1}{81}$ & $\frac{1}{243}$ & $\frac{1}{729}$ &\\[1ex]
\ldots{} & & & & & &\\[2ex]
10 & $\frac{1}{10}$ & $\frac{1}{100}$ & $\frac{1}{1000}$ & \ldots{} & & &\\
\end{tabular}