Skip to content

Instantly share code, notes, and snippets.

😸
Feeding my cat

Zeqiu Wu allenfantasy

Block or report user

Report or block allenfantasy

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View getQueryStringObject.js
const getQueryStringObject = url => {
let query = url.split('?')
if (query.length > 1) {
let params = query[1].split('&')
let values = {}
for (let i = 0; i < params.length; i++) {
let param = params[i].split('=')
values[param[0]] = param[1]
}
@allenfantasy
allenfantasy / item.vue
Last active May 17, 2018
Performance difference between render and non-render for vue list component
View item.vue
<template>
<div class="item">{{ number }}</div>
</template>
<script>
export default {
name: 'TestItem',
props: {
number: Number
}
@allenfantasy
allenfantasy / pf.conf
Created Jan 30, 2018
simple shell script to refresh pfctl for MacOS
View pf.conf
#
# Default PF configuration file.
#
# This file contains the main ruleset, which gets automatically loaded
# at startup. PF will not be automatically enabled, however. Instead,
# each component which utilizes PF is responsible for enabling and disabling
# PF via -E and -X as documented in pfctl(8). That will ensure that PF
# is disabled only when the last enable reference is released.
#
# Care must be taken to ensure that the main ruleset does not get flushed,
@allenfantasy
allenfantasy / basic.js
Last active Jan 29, 2018
Observable learning snippets. Inspired and referenced from "30天精通RxJS": https://ithelp.ithome.com.tw/articles/10187005
View basic.js
//=== Using Observable.create() ===//
import Rx from 'rxjs/Rx'
let observable = Rx.Observable
.create(observer => {
observer.next('Jerry')
observer.next('Anna')
})
// OR:
// let observable = Rx.Observable.of('Jerry', 'Anna')
// let observable = Rx.Observable.from(['Jerry', 'Anna']) // **any enumerables**
@allenfantasy
allenfantasy / sortByArr.js
Last active Nov 10, 2017
sort by another array's order
View sortByArr.js
// arr = [12,3,7]
// arr_source = [{id:1, name:'a'}, {id:2, name:'b'}, ..., {id:100, name:'xxxx'}]
// sort arr_source based on arr:
// [{id: 12, name: 'xx'}, {id: 3, name: 'xxx'}, {id: 7, name: 'xxx'}, …., {id: 100, name: 'xxxx'}]
const sortByArr = (targetArr, orderArr) => {
let ret = orderArr.slice(0)
targetArr.forEach((item,index) => {
let orderIndex = orderArr.indexOf(item.id)
if (orderIndex > -1) {
@allenfantasy
allenfantasy / ajax.js
Created Jan 22, 2016
A naive ajax function
View ajax.js
// @credit to http://stackoverflow.com/questions/8567114/how-to-make-an-ajax-call-without-jquery
function ajax(options) {
if (!options) {
throw new Error('Ajax: options is missing');
}
if (!options.url) {
throw new Error('Ajax: options.url is missing');
}
var async = options.async === undefined ? true : (!!options.async);
var type = options.type || 'GET';
View HeartView.js
function _setListeners() {
this.heartSurface.on('click', this.clickListener.bind(this));
}
function HeartView() {
View.apply(this, arguments);
_createHeart.call(this); // create HeartSurface
_setListeners.call(this);
}
View regex.js
/***** Fixed Phone Number Regex *****/
/*
Fixed phone numbers' format:
(district number)-(phone number)
*/
var phoneRegex = /^(0[\d]{2,3}-)?[\d]{7,8}$/;
phoneRegex.test("020-82376643"); //=> true
phoneRegex.test("0755-6633868"); //=> true
@allenfantasy
allenfantasy / extends.js
Last active Jun 2, 2016 — forked from hayeah/gist:9757971
Implementation of inheritance in CoffeeScript
View extends.js
var __hasProp = {}.hasOwnProperty;
var __extends = function(child, parent) {
for (var key in parent) {
if (__hasProp.call(parent, key)) child[key] = parent[key];
}
function ctor() {
// why set the prototype's constructor to child?
this.constructor = child;
}
ctor.prototype = parent.prototype;
View html5test.css
body {
font-family: 'Myriad-Pro', 'myriad', helvetica, arial, sans-serif;
text-align: center;
}
h1 {
text-align: left;
}
input { font-size: 14px; font-weight: bold; }
input[type=range]:before { content: attr(min); padding-right: 5px; }
You can’t perform that action at this time.