Skip to content

Instantly share code, notes, and snippets.

View legend80s's full-sized avatar
🎯
Focusing

legend80s

🎯
Focusing
  • Alibaba
  • Beijing
View GitHub Profile
class ColorPrinter:
"""
print message to terminal with colored header
"""
def __init__(self, header=''):
self.__header = header
self.__levels = {
'log': '\033[0m', # terminal color header
'info': '\033[1;32;40m', # green header
'warn': '\033[1;33;40m', # yellow header
@legend80s
legend80s / sieve.js
Created October 4, 2016 03:56
sieve of Eratosthenes
function sieve(n) {
const a = new Int8Array(n + 1);
const max = Math.floor(Math.sqrt(n));
let p = 2;
while (p <= max) {
for (let i = 2 * p; i <= n; i += p) {
a[i] = 1;
}
@legend80s
legend80s / generator.js
Last active March 29, 2017 10:17
Koa.js Boilerplate Generator for route, controller and model
/**
*
* @fileOverview create route/controller/model by CLI
*
* usage: `npm run generate module`
* `module` in the form of hyphen-separated
* three files will be generated:
*
* app/routes/module.js
* app/controllers/Module.js
@legend80s
legend80s / webpack.config.js
Last active October 12, 2016 11:17
Webpack config
/**
* npm install webpack css-loader extract-text-webpack-plugin file-loader html-loader style-loader html-webpack-plugin -S -E
*
* build
└── app.js
build
├── bundle.css
├── bundle.js
└── fonts
@legend80s
legend80s / hot-server.js
Last active October 13, 2016 10:11
Brower reloads on file changed
/* eslint-disable no-console */
const webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const ProgressBarPlugin = require('progress-bar-webpack-plugin');
const LogPlugin = require('./webpack-plugins/bundling-lifecycle-log-plugin');
const config = require('./webpack.config.js');
const WEB_PORT = 7002;
@legend80s
legend80s / import_to_require.py
Last active June 5, 2018 04:01
Sublime Text 2/3 plugin: transform seletion containing JavaScript's ES6 syntax `import ... from ...` to `const ... = require(...)`.
# Sublime Text 2/3 plugin
# Transform seletion containing JavaScript ES6 `import ... from ...` to `const ... = require(...)`.
#
# @example
# import react from 'react';
# // => const react = require('react');
#
# import { foo } from 'react';
# // => const { foo } = require('react');
#
@legend80s
legend80s / to_require.py
Created October 13, 2016 08:26
Transform form JavaScript's ES6 `import` to `require`.
import re
def to_require(import_str):
''' Transform form JavaScript's ES6 `import` to `require`.
>>> to_require("import webpack from 'webpack'")
"const webpack = require('webpack')"
>>> to_require('import webpack from "webpack"')
'const webpack = require("webpack")'
@legend80s
legend80s / bundling-lifecycle-log-plugin.js
Created October 13, 2016 09:39
Show Webpack Bundling Start and Stop Time
/* eslint-disable no-console */
//
// Bundle start at: 10/13/2016, 5:35:37 PM
// Bundle stop at: 10/13/2016, 5:35:43 PM
//
const colors = require('colors');
colors.setTheme({
info: 'green',
@legend80s
legend80s / update-route-entry.js
Created October 15, 2016 09:46
update-route-entry.js called by init.js
/* eslint-disable no-console */
const fs = require('fs');
function updateRouteEntry(routePath, modules) {
if (modules.length === 0) return;
fs.readFile(routePath, (err, data) => {
if (err) {
throw err;
}
@legend80s
legend80s / scopes.txt
Last active October 17, 2016 05:03 — forked from iambibhas/scopes.txt
Sublime Text 2: Snippet scopes
Here is a list of scopes to use in Sublime Text 2 snippets -
ActionScript: source.actionscript.2
AppleScript: source.applescript
ASP: source.asp
Batch FIle: source.dosbatch
C#: source.cs
C++: source.c++
Clojure: source.clojure
CoffeeScript: source.coffee