Skip to content

Instantly share code, notes, and snippets.

View SteGriff's full-sized avatar
πŸͺ΄
Springing

Stephen Griffiths SteGriff

πŸͺ΄
Springing
View GitHub Profile
@SteGriff
SteGriff / visualise-running-query-plans.sql
Created June 10, 2021 13:48
Visualise execution plans of running queries
-- QUERY TO GET RUNNING PLAN HANDLES
SELECT d.name, t.text,PLAN_HANDLE, r.total_elapsed_time/1000 RunningSeconds
FROM sys.dm_exec_requests r
JOIN sys.databases d on d.database_id = r.database_id
CROSS APPLY sys.dm_exec_sql_text(sql_handle) t
ORDER BY 4 DESC
-- VISUALISE A PLAN HANDLE
@SteGriff
SteGriff / running-queries.sql
Last active June 10, 2021 13:53
Running SQL queries
SELECT
d.name,
t.text,
r.total_elapsed_time/1000 as [Time],
r.blocking_session_id,
SUBSTRING(t.text,r.statement_start_offset/2 +1,
(CASE WHEN r.statement_end_offset = -1
THEN LEN(CONVERT(NVARCHAR(MAX), t.text)) * 2
ELSE r.statement_end_offset END -
r.statement_start_offset)/2)
@SteGriff
SteGriff / sql-connections.sql
Created June 7, 2021 09:24
SQL connections
SELECT
DB_NAME(dbid) as DBName,
COUNT(dbid) as NumberOfConnections,
loginame as LoginName
FROM
sys.sysprocesses
WHERE
dbid > 0
GROUP BY
dbid, loginame
@SteGriff
SteGriff / loader.htm
Created May 12, 2021 14:07
Pirijan's Earth Spinner
<html>
<head>
<style>
@keyframes slideMoon{0%{left:-40%}
to{left:145%}
}
@keyframes slideEarth{0%{left:-60%}
to{left:145%}
}
@SteGriff
SteGriff / fix-ng-on-init.ts
Last active January 28, 2021 19:15
Angular FormControls suck
ngOnInit(): void {
// Form field subscribes to self
// In FormGroup
this.anotherForm.controls.scoops.valueChanges.subscribe(value => {
this.anotherForm.controls.scoops.setValue(value, { onlySelf: true, emitEvent: false, emitModelToViewChange: true });
}, error => { }, () => { });
// Standalone FormControl
this.flavour.valueChanges.subscribe(value => {
@SteGriff
SteGriff / skippingIterator.js
Created October 27, 2020 15:07
Generate a sequence which skips numbers and doesn't repeat, like an offset sawtooth wave. Or odd numbers up to n, followed by even numbers up to n.
const skippingIterator = (x, skip, limit) =>
{
return 1 + ((skip * x) % limit) + (Math.floor((skip * x)/limit));
}
const limit = 36;
for (let i = 0; i < limit; i++)
{
console.log(i, skippingIterator(i, 3, limit));
}
@SteGriff
SteGriff / kanji.json
Created October 16, 2020 17:21
JSON of KANJIDIC Kanji
This file has been truncated, but you can view the full file.
[{"kanji":"亜","kun_readings":["぀.ぐ"],"on_readings":["γ‚’"],"name_readings":["γ‚„","぀ぎ","぀ぐ"],"jlpt":1,"unicode":"4e9c","heisig_en":"Asia"},{"kanji":"ε”–","kun_readings":["γŠγ—"],"on_readings":["γ‚’","γ‚’γ‚―"],"name_readings":[],"jlpt":null,"unicode":"5516","heisig_en":"babble"},{"kanji":"娃","kun_readings":["う぀く.しい"],"on_readings":["γ‚’","γ‚’γ‚€","γƒ―"],"name_readings":["い"],"jlpt":null,"unicode":"5a03","heisig_en":"fair"},{"kanji":"阿","kun_readings":["γŠγ‚‚γ­.γ‚‹","くま"],"on_readings":["γ‚’","γ‚ͺ"],"name_readings":["γ»γ¨γ‚Š","γ‚γš","あわ","γŠγ‹","きた","γͺ"],"jlpt":1,"unicode":"963f","heisig_en":"Africa"},{"kanji":"ε“€","kun_readings":["あわ.γ‚Œ","あわ.γ‚Œγ‚€","かγͺ.しい"],"on_readings":["γ‚’γ‚€"],"name_readings":[],"jlpt":1,"unicode":"54c0","heisig_en":"pathetic"},{"kanji":"ζ„›","kun_readings":["いと.しい","かγͺ.しい","め.でる","お.しむ","まγͺ"],"on_readings":["γ‚’γ‚€"],"name_readings":["あ","あし","え","かγͺ","γͺγ‚‹","めぐ","めぐみ","γ‚ˆγ—","けか"],"jlpt":2,"unicode":"611b","heisig_en":"love"},{"kanji":"挨","kun_readings":["ひら.く"],"on_readings":["γ‚’γ‚€"],"name_readings":[],"jlpt":null,"unicode":"6328","heisig_en":"s
@SteGriff
SteGriff / js-bit-packing.js
Created August 21, 2020 11:52
Bit packing in JS
const { atob, btoa } = require('abab');
function pack(bytes) {
var chars = [];
for(var i = 0, n = bytes.length; i < n;) {
chars.push(((bytes[i++] & 0xff) << 8) | (bytes[i++] & 0xff));
}
return String.fromCharCode.apply(null, chars);
}
function unpack(str) {
@SteGriff
SteGriff / hirigana-katakana.js
Created May 29, 2020 14:12
Hirigana and Katakana
window.kana = [
{"name": "n", "hiri": "γ‚“", "kata": "ン" },
{"name": "tsu", "hiri": "っ", "kata": "ッ" },
{"name": "a", "hiri": "あ", "kata": "γ‚’" },
{"name": "ka", "hiri": "か", "kata": "γ‚«" },
{"name": "ga", "hiri": "が", "kata": "ガ" },
{"name": "sa", "hiri": "さ", "kata": "γ‚΅" },
{"name": "za", "hiri": "ざ", "kata": "γ‚Ά" },
{"name": "ta", "hiri": "た", "kata": "γ‚Ώ" },
@SteGriff
SteGriff / kana-wordlist.js
Created May 27, 2020 11:45
Kana to Romaji Wordlist
// Credit: https://glitch.com/~kana-reading-practice
// https://glitch.com/@Dthurow
kanaToRomajiDict = {
"あう":{ romaji:"au", meaning:"to meet"},
"あく":{ romaji:"aku", meaning:"to open"},
"あける":{ romaji:"akeru", meaning:"to open"},
"あげる":{ romaji:"ageru", meaning:"to give"},
"あそぢ":{ romaji:"asobu", meaning:"to play"},
"あびる":{ romaji:"abiru", meaning:"to take a shower"},