Skip to content

Instantly share code, notes, and snippets.

View prendradjaja's full-sized avatar

Pandu Rendradjaja prendradjaja

View GitHub Profile
@prendradjaja
prendradjaja / bookmarklet.js
Created November 25, 2016 19:27
Lichess seek settings bookmarklet
function seekSettings(time, increment, rated, ratingRange) {
var expectedVariant = 'Standard';
var expectedTimeMode = 'Real time';
if ($('#variant').find(':selected').text() !== expectedVariant) {
alert('Failed. Set variant to: ' + expectedVariant);
return;
}
if ($('#timeMode').find(':selected').text() !== expectedTimeMode) {
alert('Failed. Set time control to: ' + expectedTimeMode);
return;
@prendradjaja
prendradjaja / snippets.js
Created November 26, 2016 01:36
Lichess bookmarklet snippets
////////////////////////////////////////////////////////////////////////////////
//// Seek modal
// Find rating...
// ...for active (currently visible) variant. Worth noting that "Standard"
// variant has multiple ratings (blitz, bullet, classical)
$('div.ratings div').filter((i, e) => e.style.display === 'block').find('strong').text()
// ...for classical
$('div.ratings div.classical strong').text()
@prendradjaja
prendradjaja / demo.rkt
Last active April 13, 2017 00:46
EBF++ demo
; Define variables a and b
:a :b
; Initialize a = 3, b = 2. $a is EBF for "go to the cell where a is stored."
$a 3+
$b 2+ ; (1) See footnotes below if you're not familiar with BF.
; Define a "pour" macro. Pour is BF's simplest version of "add". In another
; language, it might look like this: (of course, it's a macro, not a function)
;
@prendradjaja
prendradjaja / pitfall.py
Last active April 27, 2017 03:55
An easy hole to fall into using Python iterators
# coding: utf-8
x = range(4)
y = zip('1234', 'abcd')
def has_four_unique_elements(seq):
return len(set(seq)) == 4
# This works fine.
print(1, has_four_unique_elements(x)) # -> True
# Still works fine.
@prendradjaja
prendradjaja / tests.py
Last active April 16, 2018 17:56
Python unit test boilerplate (with spaces)
# https://gist.github.com/prendradjaja/35a2816c0b5750ffc91cc091e760dc00
# for version with tabs
import unittest
class TestSomething(unittest.TestCase):
def test_something(self):
pass
if __name__ == '__main__':
@prendradjaja
prendradjaja / tests.py
Last active April 26, 2017 23:58
Python unit test boilerplate (with tabs)
# https://gist.github.com/prendradjaja/a35b0dc59fb137dc71ef7703a330ab02
# for version with spaces
import unittest
class TestSomething(unittest.TestCase):
def test_something(self):
pass
if __name__ == '__main__':
@prendradjaja
prendradjaja / git-import.py
Last active May 17, 2017 21:07
Helper for putting repos on GitHub and Bitbucket
import sys
import os
assert len(sys.argv) == 3
raw_url = sys.argv[2]
class FORMATS:
BITBUCKET = 'https://bitbucket.org'
GITHUB = 'https://github.com'
@prendradjaja
prendradjaja / xkcd-permalink.js
Created May 17, 2017 21:05
xkcd permalink bookmarklet (navigates to permalink URL)
@prendradjaja
prendradjaja / medium-sort-bookmarks.js
Last active June 9, 2017 17:26
(in progress) "Sort bookmarks" bookmarklet for Medium
// https://stackoverflow.com/questions/11778477/variable-in-chrome
// https://developer.mozilla.org/en-US/docs/Web/API/Element/querySelector
var homeStream = $('.js-homeStream');
var stories = homeStream.children;
function getReadingTime (story) {
return +$('.readingTime', story).title.split(' ')[0];
}
@prendradjaja
prendradjaja / --timestamp-tag.js
Last active June 27, 2017 22:11
Timestamp for Workflowy tags (bookmarklet)
// Minifier fork (with ES6 support):
// https://jadengore.github.io/bookmarkleter/
// My usual minifier (no ES6 support): http://chriszarate.github.io/bookmarkleter/
// GitHub issue: https://github.com/chriszarate/bookmarkleter/issues/7
function main() {
prompt('Press Ctrl-C to copy', '#' + getTimeStamp());
}
function getTimeStamp() {