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
@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]);
@sloanlance
sloanlance / power.sh
Created September 26, 2017 22:26 — forked from lsloan/power.sh
When "sudo -s" just isn't enough, you need more power.
sudo /bin/env bash
@sloanlance
sloanlance / MediaWiki_TOC_float_right.css
Last active September 1, 2017 16:20
MediaWiki: CSS to make page tables of contents float on the right.
/* Begin https://example.org/path/to/wiki/MediaWiki:Common.js */
/* CSS placed here will be applied to all skins */
/* Simple CSS change to make page tables of contents float on the right of the page,
letting content wrap around it. To give a little separation from the content,
a wide white border is used instead of a transparent margin. The border color may
need to be changed to look good with other MediaWiki skins. */
/* Float table of contents (TOC) to the right, so text wraps around it */
/* Change thin gray border to a wide white one instead of using a transparent margin */
@sloanlance
sloanlance / MediaWiki_hide_TOC.js
Last active September 1, 2017 16:23
MediaWiki: Hide pages' tables of contents upon loading.
/* Begin https://example.org/path/to/wiki/MediaWiki:Common.js */
/* Any JavaScript here will be loaded for all users on every page load. */
/* This file will be included in response to requests like https://example.org/path/to/wiki/index.php?action=raw&smaxage=0&gen=js */
/* Hide the table of contents each time any page is loaded. */
function hideToc() {
try {
// Detect whether the page's TOC is displayed.
if (document.getElementById('toc').getElementsByTagName('ul')[0].style.display != 'none') {

Depersonalize JSON

Why

If JSON data is to be shared for analysis, it's often necessary to depersonalize the data first. Depersonalization is different than anonymization. If data is anonymized, all information about the user is removed. Depersonalization, however, changes the user information to values that can't be recognized as being related to the real user. This way, it's still possible to see relationships within the data.