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
/* | |
* Virtualised grid using ReactJS and RxJS. | |
* | |
* Squares in the grid have the class `visible` only when they are inside the viewport. | |
* | |
* When the container has not been scrolled for 50ms, Grid.invalidate() is | |
* called and the visibility of each of the squares is checked using getBoudingClientRect(). | |
* | |
* It is necessary to debounce the stream, otherwise this component will be horribly slow. | |
* |
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
module RPS where | |
import Data.Char (isSpace, toUpper) | |
import Data.Maybe (isNothing) | |
import Data.Text (strip) | |
data Move = Rock | Paper | Scissors | |
deriving (Show, Eq, Enum) | |
instance Ord Move where |
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
#include "linkedlist.h" | |
/* | |
* Create a new LinkedList node | |
*/ | |
node *create(int data, node *next) | |
{ | |
node *new_node = (node*)malloc(sizeof(node)); | |
if (new_node == NULL) { |
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
// Write a new zip as we don't have one in js | |
const zip = (first, second) => { | |
return [...first].map((x, i) => [x, second[i]]) | |
} | |
const match = (first, second) => { | |
const seen = new Map() | |
const zipped = zip(first, second) | |
for (let [x, y] of zipped) { |
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 collections import deque | |
class Postie: | |
def __init__(self): | |
self.__identifiers = dict() | |
def run(self): | |
"Run the calculator" | |
self.__display_intro() |
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 get_substrings(word, k): | |
"""Returns a generator containing all substrings in word of length k""" | |
for i in range(len(word) - k + 1): | |
yield word[i:i+k] | |
def k_letters_in_common(source, words, k): | |
"""Given a source word and a sequence of words, find all words in the | |
sequence that share a substring of length k with the source word. | |
Returns a list of these words (internally, a list is an array in python). |
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
function todays_note | |
set todays_note_dir (date "+$HOME/Dropbox/daily_notes/%Y/%b/") | |
set todays_filename (date '+%A-%d.md') | |
if not test -d $todays_note_dir | |
mkdir -p $todays_note_dir | |
end | |
pushd $todays_note_dir; and nvim $todays_filename; and popd | |
end |
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 pipe(*funcs): | |
return lambda initial: functools.reduce(apply, funcs, initial) | |
def apply(arg, func): | |
return func(arg) | |
if __name__ == '__main__': | |
pipe(uppercase, reverse, cipher)("hello, world!") # as an example |
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
class Object: | |
def __init__(self, *parents): | |
self.parents = [parent() for parent in parents] | |
def __getattr__(self, name): | |
for parent in self.parents: | |
if hasattr(parent, name): | |
return getattr(parent, name) | |
raise AttributeError(f"'Object' object has no attribute '{name}'") |
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
const makeLoader = (progressEl, updateProgressCount, initialProgress=0) => { | |
let progressCount = initialProgress | |
const load = () => { | |
progressCount = updateProgressCount(progressCount) | |
progressEl.value = progressCount | |
requestAnimationFrame(load) // don't need to use setTimeout - will only be called ~60 times/second | |
} | |
return load | |
} |
OlderNewer