Skip to content

Instantly share code, notes, and snippets.

@mikecao
mikecao / tradingview-multi-sma.txt
Last active May 28, 2019 02:32
Show multiple SMA values in Tradingview
//@version=3
study("Multi SMA", overlay=true)
sma1 = input(title="SMA 1", type=integer, defval=5)
sma2 = input(title="SMA 2", type=integer, defval=10)
sma3 = input(title="SMA 3", type=integer, defval=50)
sma4 = input(title="SMA 4", type=integer, defval=200)
SMA1 = sma(close, sma1)
SMA2 = sma(close, sma2)
SMA3 = sma(close, sma3)
SMA4 = sma(close, sma4)
@mikecao
mikecao / electron-menu-item-delay.html
Last active July 15, 2016 03:07
Electron menu item delay
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Electron - Test</title>
<style>
#box {
width: 100px;
height: 100px;
margin: 100px;
<!doctype html>
<html>
<head>
<style>
html, body {
width: 100%;
height: 100%;
overflow: hidden;
background-color: #ffffff;
margin: 0;
@mikecao
mikecao / javascript-canvas-sharpen.js
Created December 16, 2015 07:25
Javascript function for sharpening images.
function sharpen(ctx, w, h, mix) {
var x, sx, sy, r, g, b, a, dstOff, srcOff, wt, cx, cy, scy, scx,
weights = [0, -1, 0, -1, 5, -1, 0, -1, 0],
katet = Math.round(Math.sqrt(weights.length)),
half = (katet * 0.5) | 0,
dstData = ctx.createImageData(w, h),
dstBuff = dstData.data,
srcBuff = ctx.getImageData(0, 0, w, h).data,
y = h;
@mikecao
mikecao / javascript-inheritance
Created October 3, 2014 09:13
Simple Javascript Inheritance for ES 5.1
/* Simple JavaScript Inheritance for ES 5.1
* based on http://ejohn.org/blog/simple-javascript-inheritance/
* (inspired by base2 and Prototype)
* MIT Licensed.
*/
(function() {
"use strict";
var fnTest = /\b_super\b/;
@mikecao
mikecao / md5
Created January 30, 2014 06:19
Single function implementation of MD5 in Javascript
function md5(str) {
var i, j,
bytes = [],
words = [],
hex = [];
var Y = [7, 12, 17, 22, 5, 9, 14, 20, 4, 11, 16, 23, 6, 10, 15, 21];
var Z = [0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee,
0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
@mikecao
mikecao / psmem
Created December 3, 2012 07:12
Linux memory usage in human readable format
ps -eo size,pmem,pid,user,comm | sort -rn | head -10 | awk '{ hr[1024**2]="GB"; hr[1024]="MB"; for (x=1024**3; x>=1024; x/=1024) { if ($1>=x) { printf ("%6.2f %s ", $1/x, hr[x]); break } } } { printf ("%5s%% %-8s %-10s ", $2, $3, $4) } { for ( x=5 ; x<=NF ; x++ ) { printf ("%s ",$x) } print (" ") }'