Skip to content

Instantly share code, notes, and snippets.

View haliphax's full-sized avatar
💭
git clone self

haliphax

💭
git clone self
View GitHub Profile
#!/usr/bin/env bash
VERB=enable
KEYBOARD_ID=12
TOUCHPAD_ID=13
[ -z "$(xinput list-props 13 | grep -e 'Device Enabled.*:.*0')" ] && VERB=disable
xinput $VERB $KEYBOARD_ID
xinput $VERB $TOUCHPAD_ID
@haliphax
haliphax / flatten.py
Last active February 28, 2024 18:26
Flatten irregular array
def flatten(source):
"""
Flattens an irregular array into a single dimension.
:param list source: The array to flatten
:rtype: list
:returns: The flattened array
"""
assert isinstance(source, (list, tuple)), 'Only lists and tuples are supported'
@haliphax
haliphax / ShibbolethIISAuthModule.cs
Created November 17, 2020 00:58
Shibboleth IIS Authentication Module
/***
* Shibboleth IIS Authentication Module
*
* This module is responsible for taking two attributes from Shibboleth
* (uid, memberOf) and using them to construct a user principal that
* can be used in IIS authorization rules. Add the generated DLL to
* either the GAC or the web site's Bin folder and reference it in the
* Modules configuration for IIS.
***/
@haliphax
haliphax / LongestContiguousClickstream.cs
Created April 21, 2022 16:37
Find longest common contiguous click stream between two user records
var user0 = new string[] { "/a", "/b", "/c", "/d", "/e", "/f" };
var user1 = new string[] { "/b", "/c", "/e", "/f" };
var user2 = new string[] { "/a", "/b", "/d", "/e", "/f" };
var user3 = new string[] { "/a", "/c", "/d", "/e", "/f" };
var user4 = new string[] { "/a", "/b", "/c", "/d", "/e", "/f" };
var user5 = new string[] { "/a", "/b", "/e", "/f" };
var user6 = new string[] { "/a", "/b", "/c", "/e", "/f" };
var user7 = new string[] { "/c", "/d", "/e", "/f" };
var user8 = new string[] { "/d", "/e", "/f" };
var user9 = new string[] { "/b", "/c", "/e", "/f" };
@haliphax
haliphax / ProperCase.fs
Last active February 28, 2024 18:25
Capitalize a given string using Proper Case (dipping a toe into the F# water)
// capitalizes the first letter of every word in the given string
let properCase (s:string) =
// recursive helper function
let rec helper (s:string) (i:int) (capitalize:bool) (result:string) =
// if we're at the end of the string, return our result
if s.Length - 1 < i then
result
else
// recurse to the next character in the input string
(helper s (i + 1) (s.[i] = ' ') (result +
@haliphax
haliphax / SumFile.fs
Last active February 28, 2024 18:25
Sum all of the lines in a given file which are integers
open System.IO
// sums up all of the lines in a given file
let sumFile (fileName:string) =
// wrapper for catching int conversion exceptions
let wrapper (sr:System.IO.StreamReader) =
try
int (sr.ReadLine())
with
| :? System.FormatException -> 0
@haliphax
haliphax / random-string.js
Created October 30, 2023 21:17
generate random string
/** printable ASCII characters */
const ascii = [];
for (let i = 33; i <= 126; ascii.push(String.fromCharCode(i++)));
/** generate random string */
const randomString = limit => {
const result = [];
for (let i = 0; i < limit; i++) {
const index = Math.floor(Math.random() * (126 - 33) + 33);
@haliphax
haliphax / install-gitmoji-hook.sh
Last active September 11, 2023 04:55
Gitmoji CLI commit hook
#!/usr/bin/env bash
# install gitmoji as a commit hook
#
# - uses https://www.npmjs.com/package/gitmoji-cli
# - does not require global module installation
# - skips hook if message already starts with gitmoji
root="$(git rev-parse --show-toplevel)"
hook="$root/.git/hooks/prepare-commit-msg"
@haliphax
haliphax / 11ty-transform-htmlMinify.ts
Created August 3, 2023 19:17
Eleventy - HTML and inline script minifier transform
import { UserConfig } from "@11ty/eleventy";
import { DOMParser } from "@xmldom/xmldom";
import { transform } from "esbuild";
import { minify } from "html-minifier";
/** cache for content of script tags with an ID */
const scriptCache = new Map<string, string>();
/** DOM parser for navigating the rendered document; warnings are ignored */
const parser = new DOMParser({ errorHandler: { warning: () => {} } });

Keybase proof

I hereby claim:

  • I am haliphax on github.
  • I am haliphax (https://keybase.io/haliphax) on keybase.
  • I have a public key ASC0LFekXGTz3OedyiQZMCgD_CiApPRAvykdZJCJsqv5wgo

To claim this, I am signing this object: