Skip to content

Instantly share code, notes, and snippets.

Lance E Sloan sloanlance

Block or report user

Report or block sloanlance

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@sloanlance
sloanlance / three_reasons.bas
Last active Dec 10, 2018
"Three Reasons To Own a Computer" for Commodore 64, from Compute!'s Gazette (via https://www.lemon64.com/forum/viewtopic.php?p=429351&sid=a78679bc4b8671443f9300905275b9e5#429351)
View three_reasons.bas
0 REM "THREE REASONS TO OWN A COMPUTER" FOR COMMODORE 64
1 REM FROM COMPUTE!'S GAZETTE
10 FORL=54272 TO 54295:POKEL,0:NEXT:POKE54296,15
20 POKE54277,8:POKE54278,255:POKE54276,23
30 F2=4
40 FORZ=1TO3:POKE54287,F2
50 FORF1=1TO200
60 POKE54273,F1:F2=F2+.01:NEXTF1:NEXTZ:POKE54278,15
@sloanlance
sloanlance / accessEncapsulation.py
Created Jul 19, 2018
Python: Class member access enforcement (not encapsulation)
View accessEncapsulation.py
# From Stack Overflow question:
# https://stackoverflow.com/questions/26216563/how-to-do-encapsulation-in-python
#
# Python has simple encapsulation, but it doesn't strictly enforce access to
# protected or private class members. This is one person's attempt to
# address that in a (misleadingly named) class.
#
# Could this be done with introspection rather than using on `self.privates` and
# `self.protected`? Follow the common Python style of naming variables `__a` and `_b`.
# Then the methods would check whether the names begin with `__` or `_` to allow or
View display_system.ipynb
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 May 23, 2018 — forked from magicznyleszek/jekyll-and-liquid.md
Jekyll & Liquid Cheatsheet (A fork of the gist by "magicznyleszek", FKA "smutnyleszek")
View Jekyll & Liquid Cheatsheet
See: `Jekyll & Liquid Cheatsheet.md`
@sloanlance
sloanlance / jq_tsv_conversion.md
Last active Mar 8, 2018
jq: JSONL → TSV conversion
View jq_tsv_conversion.md

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 Aug 16, 2019
jq: JSONL ↔︎ JSON conversion
View jq_jsonl_conversion.md

jq: JSONL ↔︎ JSON conversion

  1. JSONL → JSON

    jq -s '.' input.jsonl > output.json
    
  2. JSON → JSONL

    jq -c '.[]' input.json > output.jsonl
    
@sloanlance
sloanlance / pseudorandom_alphabetical_string.js
Last active Feb 15, 2018
JS: pseudorandom alphabetical string
View pseudorandom_alphabetical_string.js
// "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 Jan 22, 2018 — forked from SpaceVoyager/pythonista_compile_howto.md
How to make a standalone iOS app with Pythonista
View pythonista_compile_howto.md

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 Jan 15, 2018
PHP: A replacement for the shamefully broken DateTime::getTimestamp
View getTimestampWithFraction.php
/**
* 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 Dec 21, 2017
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).
View Karabiner: Require fn for esc
Please see the README.md file in this gist.
You can’t perform that action at this time.