Skip to content

Instantly share code, notes, and snippets.

View mondaychen's full-sized avatar

Mengdi Chen mondaychen

View GitHub Profile
@mondaychen
mondaychen / gist:1598350
Created January 12, 2012 03:17 — forked from getify/gist:670840
using LABjs to load from a CDN, with simple error detection (& timeout), and a local load fallback
function loadOrFallback(scripts,idx) {
var successfully_loaded = false;
function testAndFallback() {
clearTimeout(fallback_timeout);
if (successfully_loaded) return; // already loaded successfully, so just bail
try {
scripts.tester();
successfully_loaded = true; // won't execute if the previous "test" fails
scripts.success();
// console.log("success: " + scripts.src[idx]);
p{
width: 220px;
margin: 0;
}
@mondaychen
mondaychen / Stacking_rectangles.py
Last active August 29, 2015 14:17
Stacking rectangles
def lcs(x, y):
n = len(x)
m = len(y)
table = dict() # a hashtable, but we'll use it as a 2D array here
for i in range(n+1): # i=0,1,...,n
for j in range(m+1): # j=0,1,...,m
if i == 0 or j == 0:
table[i, j] = 0
elif x[i-1] == y[j-1]:
import math
def kthPrime(k):
# k is non-negative
if k < 0:
return None
# an array to store primes
primes = []
# use an array of booleans `isPrime` to indicate whether a number is a prime
# e.g. isPrime[2] is True means 2 is a prime
# upperLimit is the size of the array. We start from a small number
@mondaychen
mondaychen / page-scroll-blog.js
Created February 11, 2016 00:10
Page Scroll Workaround for Single-Page Apps
var $container = $('#container');
...
// when some route is matched
var view = new AnotherPage();
$container.html(view.render().el);
window.scrollTo(0, 0);
$container.html(el)
// jump to top if needed
@mondaychen
mondaychen / sparks-from-redux.md
Last active June 4, 2022 03:16
Sparks from Redux

Sparks from Redux

##Intro to Redux

###Some important concepts of Redux

Reference: Three Principles, Basics

  • A single Store to maintain the state tree
const lodash = require('lodash');
const { random } = lodash;
const online = []
const offline = []
const afk = []
function addPlayer(set, fixPower) {
set.push({
power: fixPower || random(1, 1000, true),
@mondaychen
mondaychen / K10.js
Last active November 16, 2020 14:40 — forked from rsalzer/RandomWikimediaPicture.js
Scriptable-Script to open zoom link for my daughter
function runScriptable() {
const [title, link] = getZoomInfo(new Date());
const widget = createWidget(title, null, link);
if (config.runsInWidget) {
Script.setWidget(widget);
Script.complete();
} else {
widget.presentSmall();
}
@mondaychen
mondaychen / .vimrc
Last active April 24, 2023 04:16 — forked from simonista/.vimrc
A basic .vimrc file that will serve as a good template on which to build.
" Don't try to be vi compatible
set nocompatible
" Helps force plugins to load correctly when it is turned back on below
filetype off
" TODO: Load plugins here (pathogen or vundle)
" Turn on syntax highlighting
syntax on
@mondaychen
mondaychen / 2023年终总结.md
Last active December 31, 2023 00:20
2023年终总结


2023:不可思议的幸运之年

写在最前面

我一直很佩服能坚持写作的人。我自己写东西的时候八成都是这样的三部曲:产生强烈的表达冲动——越写越觉得自己的想法和表达有缺失——把半成品忘在草稿箱里。
今年我下决心无论如何都要把年终总结写出来,因为在生活的方方面面都发生了太多重要的事了。但是写着写着又开始自我怀疑:说了这么多事,好像每个都有点感悟,又每个都没写清楚,这算个什么哪门子的文章?正这么想的时候在推特上看到了 Rick Rubin 的一个视频叫作《How to deal with a creative block》。他鼓励内容创作者写东西就当作写日记,只为自己一个人写,认真写,不用为别人负责。
谢谢 Rubin,谢谢宇宙。这篇总结我就为了自己写。