Skip to content

Instantly share code, notes, and snippets.

View sloanlance's full-sized avatar
Certified GitHub Pro

Mr. Lance E Sloan sloanlance

Certified GitHub Pro
View GitHub Profile
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@sloanlance
sloanlance / Jekyll & Liquid Cheatsheet
Last active September 17, 2022 11:33 — forked from magicznyleszek/jekyll-and-liquid.md
Jekyll & Liquid Cheatsheet (A fork of the gist by "magicznyleszek", FKA "smutnyleszek")
See: `Jekyll & Liquid Cheatsheet.md`
@sloanlance
sloanlance / jq_tsv_conversion.md
Last active March 21, 2025 01:47
jq: JSONL → TSV conversion

jq: JSONL → TSV conversion

What is TSV?

TSV means "tab-separated values". I prefer this format over CSV ("comma-separated values") because it doesn't require as much quoting. Many programs that can use CSV formatted data can also use TSV, although they may need to be explicitly told of the different format if it's not detected automatically.

However, in any of the jq scripts below, "@tsv" can usually be replaced with "@csv" to get CSV output instead.

@sloanlance
sloanlance / jq_jsonl_conversion.md
Last active July 23, 2025 10:01
jq: JSONL ↔︎ JSON conversion

jq: JSONL ↔︎ JSON conversion

Prerequisites

  • jqhttps://jqlang.org/ — "like sed for JSON data"

    There are several options available for installing jq. I prefer to use Homebrew: brew install jq

  • JSONL → JSON

@sloanlance
sloanlance / pseudorandom_alphabetical_string.js
Last active February 15, 2018 18:21
JS: pseudorandom alphabetical string
// "Pseudorandom", because it's not guaranteed to be truly random.
// Express a floating point random number as base 26 and remove "0." from the beginning.
// Next, to make it alphabetical, replace digits 0-9 with letters q-z.
// @returns {string} Usually 10 to 13 characters in length
Math.random().toString(26).substring(2).replace(/[0-9]/g, function (c) {return 'qrstuvwxyz'[c]});
// Alternate, non-function versions (which is more efficient?)
Math.random().toString(26).substring(2).split('').map(c => 'qrstuvwxyz'[c] || c).join(''); // split to array, replace, join to string
Math.random().toString(26).substring(2).replace(/[0-9]/g, c => 'qrstuvwxyz'[c]); // examine only characters 0-9
Math.random().toString(26).substring(2).replace(/./g, c => 'qrstuvwxyz'[c] || c); // examine all characters
@sloanlance
sloanlance / pythonista_compile_howto.md
Created January 22, 2018 03:43 — forked from SpaceVoyager/pythonista_compile_howto.md
How to make a standalone iOS app with Pythonista

After you made some cool games or apps with Pythonista, you may want to make it run as a standaone app on iPad/iPhone and possibly share it on the AppStore. This how-to tells you how to do it.

What you need:

  1. Pythonista code you wrote
  2. A Mac with Xcode 7.1 installed
  3. iPhone/iPad running iOS 9

Steps:

  1. Download PythonistaProjectTemplate.zip. The original PythonistaProjectTemplate described at http://olemoritz.net/pythonista-15-whats-new-and-whats-missing.html does not work with Xcode 7. I updated it to work with Xcode 7 and added a more interesting example than the plain old Hello World thing.
  2. Unzip the file and open the project in Xcode 7.1. In project settings, change the Bundle Identifier from com.yuhangwang.pythonistaproject to something else.
@sloanlance
sloanlance / getTimestampWithFraction.php
Created January 15, 2018 20:30
PHP: A replacement for the shamefully broken DateTime::getTimestamp
/**
* Problem: `DateTime::getTimestamp` returns **_`int`_**! Calculations such as the following
* are incorrect if the `DateTime` object includes fractions of seconds:
*
* ```php
* $durationSeconds = strval($endTime->getTimestamp() - $startTimestamp);
* ```
*
* `DateTime::diff` can subtract properly, but only under PHP 7.1. (Curiously,
* `DateTime::getTimestamp` still returns `int` under PHP 7.1!)
@sloanlance
sloanlance / Karabiner: Require fn for esc
Last active December 21, 2017 17:10
Karabiner: Require fn modifier key to activate esc key. Useful for preventing accidental esc keypresses on Macs with a Touch Bar. Doesn't affect all other modifier combinations (i.e., option + command + esc works without requiring fn, too).
Please see the README.md file in this gist.
@sloanlance
sloanlance / MacBook Pro Touch Bar.md
Created December 19, 2017 18:30
MacBook Pro Touch Bar - How to cope

Coping with a Touch Bar on a MacBook Pro

  1. Install Karabiner-Elements: https://pqrs.org/osx/karabiner/
  2. In Karabiner-Elements' preferences
    1. Disable the Touch Bar's esc key
      1. Simple Modifications
        1. Target Device: "No product name (No manufacturer name)", is the Touch Bar
          • From key: escape
          • To key: vk_none (disable this key)
    2. Make `~ act as esc and fn + `~ act as `~
@sloanlance
sloanlance / PHP Timezone Constants
Last active October 27, 2017 16:01
#PHP – A note I added to the PHP manual about timezone constants. http://php.net/manual/en/function.date-default-timezone-set.php#121800
date_default_timezone_set(DateTimeZone::listIdentifiers(DateTimeZone::UTC)[0]);