Skip to content

Instantly share code, notes, and snippets.

View banyudu's full-sized avatar
🎯
Focusing

Yudu banyudu

🎯
Focusing
View GitHub Profile
@banyudu
banyudu / wifi_share_windows
Created June 29, 2016 06:46
Share wifi on windows
netsh wlan stop hostednetwork
netsh wlan set hostednetwork mode=allow ssid=yourssid key=yourkey
netsh wlan start hostednetwork
@banyudu
banyudu / device2uuid
Created June 29, 2016 06:51
convert devices to uuid in /etc/fstab
#!/usr/bin/perl
use warnings;
use strict;
# 这个程序用来把/etc/fstab 文件的挂载项由 /dev/sd* 这样的标志改成uuid的标志
# 修改的好处是不会因为非Linux上的分区的增加或者删除而导致的无法正常启动或正常挂载分区
# 要求超级用户的权限
print "程序运行需要超级用户的权限,尝试以root用户或者sudo方式运行\n"
and exit 1 if $< !=0;
@banyudu
banyudu / something.js
Created March 18, 2017 03:47
Sequelize model integrates with cache
'use strict';
const fs = require('fs');
module.exports = function(sequelize, DataTypes) {
const tableName = 'something';
const attr = JSON.parse(fs.readFileSync(__dirname + `/attributes/${tableName}`));
const Something = sequelize.define('Something',attr, {
classMethods: {
getCacheFields: () => { return ['field1', 'field2', 'field3'] } // fields you want to cache
@banyudu
banyudu / proxyGetDBRecord.js
Created March 18, 2017 03:55
proxy get method for db record in cache
Cache.proxyGetDBRecord = function *(model, id, field) {
if (!id) {
return null;
}
let key = genCacheKeyWithModel(model, id); // generate id with tableName and id
let result = null;
if (field) {
result = yield client.hgetAsync(key, field);
} else {
@banyudu
banyudu / useProxyGetDBRecord.js
Created March 18, 2017 04:00
usage of proxyGetDBRecord
let name = yield* cache.proxyGetDBRecord(db.Something, id, 'name');
let record = yield* cache.proxyGetDBRecord(db.Something, id);
@banyudu
banyudu / launch.js
Last active March 22, 2017 08:54
vscode launch.js for mocha test, copied from https://gist.github.com/paambaati/54d33e409b4f7cf059cc
{
"name": "Run mocha",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
"stopOnEntry": false,
"args": ["test/**/*.js", "--no-timeouts"],
"cwd": "${workspaceRoot}",
"runtimeExecutable": null,
"env": { "NODE_ENV": "testing"}
@banyudu
banyudu / ts_launch.json
Last active March 30, 2017 08:34
launch.json for typescript
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch",
"program": "${workspaceRoot}/index.ts",
"sourceMaps": true,
"outFiles": []
const sequelize = require('sequelize')
const db = new sequelize('test', 'test', '', {
dialect: 'postgres',
host: '127.0.0.1',
port: 5432,
})
const Foo = db.define('foo')
const Bar = db.define('bar')
@banyudu
banyudu / get_method_names_from_class.js
Created September 6, 2017 08:43
Get method names from class in javascript
class User {
constructor() {
// do nothing
}
*createUser(params) {
// TODO: implement this function
}
*getUser(params) {
import Chance = require('chance')
interface IChance extends Chance.Chance {
password(): string
}
export const chance = new Chance() as IChance
// mixins
chance.mixin({