Skip to content

Instantly share code, notes, and snippets.

'use strict';
const arrayProto = Array.prototype;
const arrayMethods = Object.create(arrayProto);
const newArrProto = [];
['push','pop','shift','unshift','splice','sort','reverse'].forEach(function (method) {
let original = arrayMethods[method];
var worker = new Worker("worker.js");
worker.postMessage(
{
id:1,
msg:'Hello World'
}
);
worker.onmessage=function(message){
var data = message.data;
document.write(data.msg);
@edwardwbli
edwardwbli / react-ajax.js
Created January 16, 2017 03:53
Sampel for react component to use ajax to call api and then update state (JSX, need babel for translation)
var CommentBox = React.createClass({
getInitalState: function() {
return {data: []};
},
componentDidMount: function() {
$.ajax({
url: this.props.url,
dataType: 'json',
success: funciton(data) {
this.setState({data: data});
<!DOCTYPE html>
<html>
<head>
<title>React-App</title>
<script src="https://unpkg.com/react@15.3.2/dist/react.js"></script>
<script src="https://unpkg.com/react-dom@15.3.2/dist/react-dom.js"></script>
<style media="screen" type="text/css">
.todocontent, .inprogresscontent {
float: left;
position: relative;
@edwardwbli
edwardwbli / gundb_jquery.html
Created January 11, 2017 07:03
example for Jquery to use Gundb
<html>
<body>
<h1>Thoughts</h1>
<form>
<input><button>Add</button>
</form>
<ul></ul>
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
@edwardwbli
edwardwbli / react-createElement.html
Last active January 10, 2017 06:37
this a example for using createElement in react.
<!DOCTYPE html>
<html>
<head>
<title>ToDo</title>
<script src="https://cdn.rawgit.com/amark/gun/master/gun.js"></script>
<script src="https://unpkg.com/react@15.3.2/dist/react.js"></script>
<script src="https://unpkg.com/react-dom@15.3.2/dist/react-dom.js"></script>
<style media="screen" type="text/css">
.todocontent, .inprogresscontent {
float: left;
@edwardwbli
edwardwbli / load_test_data.sh
Created August 26, 2016 06:17 — forked from clintongormley/load_test_data.sh
Run these commands in your shell to setup the test data for Chapter 5
curl -XPUT 'http://localhost:9200/us/user/1?pretty=1' -d '
{
"email" : "john@smith.com",
"name" : "John Smith",
"username" : "@john"
}
'
curl -XPUT 'http://localhost:9200/gb/user/2?pretty=1' -d '
{
@edwardwbli
edwardwbli / GImgDL.py
Created February 23, 2012 17:18
Google image downloader
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys,os,re,urllib
folder="e:\image\\"
reg=re.compile("((?<=imgurl=)http.*?\.(jpg|gif|png|bmp|jpeg))")#正则表达式匹配下载地址
reg2=re.compile("((?<=/)[^/]*?\.(jpg|gif|png|bmp|jpeg))")
fd=open('image.htm','r')
html=fd.read()
fd.close()
@edwardwbli
edwardwbli / BImgDL.py
Created February 23, 2012 17:17
baidu image downloader
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys,os,re,urllib
folder="e:\image\\"
reg=re.compile("((?<=\"objURL\"\:\")http.*?\.(jpg|gif|png|bmp|jpeg))")#正则表达式匹配下载地址
reg2=re.compile("((?<=/)[^/]*?\.(jpg|gif|png|bmp|jpeg))")
fd=open('image3.htm','r')
html=fd.read()
fd.close()
@edwardwbli
edwardwbli / My Emacs configuration
Created December 6, 2011 16:37
My Emacs configuration
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(show-paren-mode t)
'(text-mode-hook (quote (text-mode-hook-identify))))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.