Skip to content

Instantly share code, notes, and snippets.

@ylt6
ylt6 / tampermonkey_text_replacement_script.js
Created June 27, 2024 18:07
tampermonkey_text_replacement_script
(function() {
var replaceArry = [
[/replaceme/gi, 'newtext'],
];
function replace_text() {
var numTerms = replaceArry.length;
var txtWalker = document.createTreeWalker(
document.body,
NodeFilter.SHOW_TEXT, {
@ylt6
ylt6 / puzzle_348371419980095.py
Last active December 6, 2021 08:05
Scoreboard Inference (Chapter 1)
# https://www.facebookrecruiting.com/portal/coding_puzzles/?puzzle=348371419980095
from typing import List
# Write any import statements here
def getMinProblemCount(N: int, S: List[int]) -> int:
# Write your code here
is_even = lambda x: True if x % 2 == 0 else False
@ylt6
ylt6 / 1320.py
Last active March 10, 2020 22:22
# https://leetcode.com/problems/minimum-distance-to-type-a-word-using-two-fingers/
from string import ascii_uppercase
class Solution:
def __init__(self):
anchor = ord('A')
self.keyboard = {c: ((ord(c) - anchor) // 6, (ord(c) - anchor) % 6) for c in ascii_uppercase}
self.memo = {}
@ylt6
ylt6 / test.py
Created February 25, 2020 15:13
solution
class Solution:
def addOperators(self, num, target):
length = len(num)
ret = []
def rdfs(curr_index, curr_calculate, curr_expr):
if curr_index >= length:
if curr_calculate == target:
ret.append(curr_expr)
@ylt6
ylt6 / .vimrc
Created April 1, 2019 10:14
.vimrc
syntax enable
"line numbers
set number
set relativenumber
augroup numbertoggle
autocmd!
autocmd BufEnter,FocusGained,InsertLeave * set relativenumber
autocmd BufLeave,FocusLost,InsertEnter * set norelativenumber
augroup END
@ylt6
ylt6 / simple_kv_store.sh
Created December 24, 2018 14:13
simple_kv_store.sh
#!/bin/bash
db_set() {echo "$1,$2" >> database}
db_get() {grep "^$1," database | sed -e "s/^$1,//" | tail -n 1}
@ylt6
ylt6 / .zshrc
Created October 19, 2018 12:33
export ZPLUG_HOME=$HOME/.zplug
local zplug_init=$ZPLUG_HOME/init.zsh
if [ ! -f "$zplug_init" ] &> /dev/null; then
curl -sL --proto-redir -all,https https://raw.githubusercontent.com/zplug/installer/master/installer.zsh| zsh
fi
source $zplug_init
zplug 'zplug/zplug', hook-build:'zplug --self-manage'
zplug "robbyrussell/oh-my-zsh", use:"lib/{clipboard,completion,directories,history,termsupport,key-bindings}.zsh"
zplug "plugins/zsh_reload", from:oh-my-zsh
@ylt6
ylt6 / heap_sort.py
Last active May 26, 2018 12:57
heap_sort
# coding=utf-8
import random
import math
def max_heapify(A, index):
left_index = index * 2
right_index = left_index + 1
@ylt6
ylt6 / document_distance.py
Last active April 10, 2018 14:16
courses.csail.mit.edu/6.006/fall11/lectures/lecture2
import sys
import math
def make_words(document):
return document.split()
def make_frequency(document):
frequency = {}
for w in make_words(document):
if w in frequency:
@ylt6
ylt6 / test_trie.js
Created November 29, 2017 15:08
check_tie_memory_usage
const createTrie = require('autosuggest-trie');
const sizeOf = require('object-sizeof');
// sample data
const locations = [
{
id: 1,
name: 'East Richmond 1234 VIC',
population: 10000
},