Skip to content

Instantly share code, notes, and snippets.

View coderek's full-sized avatar
👽

Derek Zeng coderek

👽
View GitHub Profile
static List<Integer> search(String pattern, String text) {
int[] pi = buildTable(pattern);
return kmpSearch(text, pattern, pi);
}
static List<Integer> kmpSearch(String text, String pattern, int[] pi) {
List<Integer> res = new ArrayList<>();
int p = 0;
for (int i=0;i<text.length();i++) {
while (p>0 && text.charAt(i) != pattern.charAt(p)) {
var s = new BouncingCanvasShapesStage();
var option = {
particleWidth: 10,
particleHeight: 10,
};
var benchmark = new BouncingCanvasShapesBenchmark(
{
// controller: 'adaptive',
// "test-interval": 1000,
complexity: 200,
Ria 89.7 | http://mediacorp.rastream.com/897fm
Gold 90.5 FM | http://mediacorp.rastream.com/905fm
91.3 Hot FM | http://sph.rastream.com/913fm
Kiss 92.0 | http://sph.rastream.com/sph-kiss92
Symphony 92.4 | http://mediacorp.rastream.com/924fm
Yes 93.3 | http://mediacorp.rastream.com/933fm
93.8 Live | http://mediacorp.rastream.com/938fm
Warna 94.2 | http://mediacorp.rastream.com/942fm
Class 95.0 | http://mediacorp.rastream.com/950fm
95.8 Capital | http://mediacorp.rastream.com/958fm
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>index</title>
</head>
<body>
<label for="Input">Input</label>
<input type="text" name="Input" value="" id="Input">
<ul id="suggestions">
// https://stackoverflow.com/questions/9272232/fft-library-in-android-sdk
public class FFT {
int n, m;
// Lookup tables. Only need to recompute when size of FFT changes.
double[] cos;
double[] sin;
@coderek
coderek / index.html
Last active March 26, 2018 02:48
Vue 2.0 - 2 way data binding deeper analysis
<!DOCTYPE html>
<html>
<head>
<title>Test 2 way data binding</title>
</head>
<body>
<div id="app">{{ abc }} - {{ def }} = {{ abc-def }} </div>
<button id='add'>add</button>
<button id='double'>double</button>
<script src='main.js'></script>
@coderek
coderek / threading.py
Last active July 25, 2017 02:46
threading and synchronization
import time
from random import random
from threading import Thread, Lock
"""
Python's GIL ensures that non IO ops will execute sequentially
So no need to sync the followings
s = store + 1
store = s
@coderek
coderek / win.vimrc
Last active October 6, 2017 20:06
vimrc for windows
set nocompatible " be iMproved, required
set rtp+=$HOME/.vim/bundle/Vundle.vim
filetype off " required
" set the runtime path to include Vundle and initialize
call vundle#begin('$HOME/.vim/bundle/')
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
@coderek
coderek / kmp_search.py
Last active October 17, 2017 03:18
finding repeated string using kmp
def kmp(text, word):
wl = len(word)
jump = [0 for _ in range(wl)]
j = 0
i = 1
while i < wl:
if word[i] == word[j]:
jump[i] = j + 1
i+=1