Skip to content

Instantly share code, notes, and snippets.

View axetroy's full-sized avatar
💭
Get busy living or get busy dying

Axetroy axetroy

💭
Get busy living or get busy dying
View GitHub Profile
@axetroy
axetroy / observer.js
Last active April 24, 2017 09:44
简单的发布订阅者模式的实现
var Observer = function () {
};
Observer.prototype = {
constructor: Observer,
subscribe: function (eventName, func) {
if (!this[eventName]) this[eventName] = [];
this[eventName].push(func);
},
@axetroy
axetroy / date2ChineseHumanize.js
Last active April 25, 2017 01:50
将日期转化为中文可读性的日期,如:二〇一五年三月十二日 星期三 五时三十八分
function date2ChineseHumanize(date) {
let DATE_CN = ['〇', '一', '二', '三', '四', '五', '六', '七', '八', '九'];
let DATE_UNIT = ['年', '月', '日', '星期', '时', '分', '秒'];
let dateArr = [
date.getFullYear(), // 年
date.getMonth() + 1, // 月
date.getDate(), // 日
date.getDay(), // 星期
date.getHours(), // 小时
date.getMinutes(), // 分钟
@axetroy
axetroy / parser.js
Last active April 25, 2017 01:54
解析多层属性,类似angularJS的$parse服务
function parse(properties) {
const agm = properties.split('.');
return function(target, undefined) {
let result = null;
(function parseTarget(target, agm) {
if (target === void 0) {
console.error(
'Uncaught TypeError: Cannot read property ' + agm[0] + ' of undefined'
);
@axetroy
axetroy / diff-time.js
Created April 25, 2017 02:32
计算两个时间点的时间差
function diffTime(time1) {
return function(time2) {
let seconds = Math.abs(time1 - time2) / 1000;
const days = Math.floor(seconds / (3600 * 24));
seconds = seconds - days * 3600 * 24;
const hours = Math.floor(seconds / 3600);
seconds = seconds - hours * 3600;
const minutes = Math.floor(seconds / 60);
@axetroy
axetroy / point.js
Last active April 26, 2017 09:54
坐标系中如何最快确定距离最近/远的两个点, 如果选择一条最优路线
class Point {
constructor(x, y) {
this.x = x;
this.y = y;
}
distance(point) {
const diffX = Math.abs(point.x - this.x);
const diffY = Math.abs(point.y - this.y);
return Math.sqrt(Math.pow(diffX, 2) + Math.pow(diffY, 2));
}
@axetroy
axetroy / README.md
Created June 12, 2017 02:17
Linux下的smb配置

因为开发中有协同需求,需要远程修改另一台电脑上的文件.

如果使用默认的smb配置,则会有写入权限问题: 既文件权限改成写入人

例如A要去改B电脑上的文件

A改了文件之后,文件的所有权变成了A的,而B没有该文件的权限,这会导致一些问题.

摸索了一下,解决了这个问题

@axetroy
axetroy / README.md
Created June 26, 2017 01:54
Github两步验证的恢复码

经过最严格的加密算法加密

用于恢复无法使用两步验证的情况

@axetroy
axetroy / README.md
Created June 27, 2017 06:53
List of languages that compile to JS
@axetroy
axetroy / .bashrc
Created July 7, 2017 07:34
Bash Config
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
@axetroy
axetroy / README.md
Last active September 26, 2017 03:05
解决Linux下因防火墙问题无法开放端口

暂时开放所有

iptables -I INPUT -j ACCEPT