// This import should come before React import
import './react-amnesia-checker.ts';
import React from 'react';
import ReactDOM from 'react-dom';
ReactDOM.render(...);
This little app shows the number of unread GitHub notifications in macOS menu bar.
There are other similar apps, but they either run a full fucking Electron, or have too many other features and look busy.
- Download and install xbar (beta version is fine). It's a small app that allows you to add output of any script (Bash, Python, JS) to the menu bar.
- Launch it, go to the menu, enable "Start at Login".
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def swap(matrix, r1, c1, r2, c2): | |
matrix[r1][c1], matrix[r2][c2] = matrix[r2][c2], matrix[r1][c1] | |
def transpose(matrix): | |
for row in range(len(matrix)): | |
for col in range(row): | |
swap(matrix, row, col, col, row) | |
def flip_vertical(matrix): | |
size = len(matrix) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from http.server import HTTPServer, SimpleHTTPRequestHandler | |
# In Python 2 http.server is called BaseHTTPServer | |
class RequestHandler(SimpleHTTPRequestHandler): | |
def do_GET(self): | |
command = self.path[1:] | |
if command == 'wakeup': | |
response = 'Time to wake up!' | |
else: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socketserver # In Python 2 use "import SocketServer" instead | |
class RequestHandler(socketserver.StreamRequestHandler): | |
def handle(self): | |
command = self.rfile.readline()[5:-11].decode('UTF-8') | |
print(command) | |
if command == 'sleep': | |
self.respond('Going to sleep') | |
elif command == 'wakeup': |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.Bits | |
collatzLen :: Int -> Int -> Int | |
collatzLen len x | |
| x == 1 = len | |
| testBit x 0 = collatzLen (len + 2) (shiftR (3*x + 1) 1) | |
| otherwise = collatzLen (len + 1) (shiftR x 1) | |
main = print . snd . maximum $ [(collatzLen 0 x, x) | x <- [500000..1000000]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Minimize the number of drops required in the worst case and return [floor, drops] - | |
// the floor we should choose and the number of drops we'll have to make in the | |
// worst case. | |
function minMaxDrops(buildingHeight, marbles, cache) { | |
if (marbles == 0) { | |
return [0, Infinity]; | |
} | |
if (marbles == 1) { | |
// If we have just 1 marble, the only option is to start at the bottom floor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Examples: | |
// parseQueryString('a=1&a=2') => {a: '2'} | |
// parseQueryString('a=1', true) => {a: ['1']} | |
// parseQueryString('a=1&a=2', true) => {a: ['1', '2']} | |
// parseQueryString('a[][]=1&a[][]=2', true) => {'a[][]': ['1', '2']} | |
// parseQueryString('?a;b#c') => {'?a': '', 'b#c': ''} | |
function parseQueryString(query, groupByName) { | |
var parsed, hasOwn, pairs, pair, name, value; | |
if (typeof query != 'string') { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Scroll to selection focus, but only if it's out of view. Align selection | |
// focus with the top or bottom edge of its scroll-container. Return true | |
// on success. | |
// * there might be several nested scroll-containers, including window | |
// * must not try to scroll overflow:hidden and overflow:visible elements | |
// * no scrolling should happen if selection focus is visible | |
// * selection is not necessarily collapsed | |
// * range.getBoundingClientRect doesn't work for collapsed ranges | |
// * Opera reports incorrect startOffset and endOffset for collapsed ranges | |
// outside of text nodes (e.g. between 2 <br> elements), range.insertNode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python port of Rob Pike's regexp matcher from 'The Practice of Programming' | |
# Idea for match() stolen from https://github.com/darius/sketchbook/blob/master/misc/pike.py | |
def match(re, text): | |
""" | |
Search for regexp anywhere in text | |
c - any literal character | |
. - any single character | |
^ - the beginning of the input string | |
$ - the end of the input string |