Skip to content

Instantly share code, notes, and snippets.

View xixilive's full-sized avatar
🌴
On vacation

xixilive xixilive

🌴
On vacation
View GitHub Profile
@xixilive
xixilive / routing_marcors.rb
Last active August 29, 2015 14:00
Restful routing spec macor
module RoutingMacors
CRUD = { index: :get, show: :get, new: :get, edit: :get, update: :put, create: :post, destroy: :delete }
def have_restful_resource *resources
faked_id = Time.now.to_i.to_s
options = resources.extract_options!
collection_name = resources.last.to_s.pluralize
ancestors = resources[0..-2].collect{|ancestor| [ancestor.to_s.pluralize, faked_id] }.join("/")
actions = CRUD.keys
@xixilive
xixilive / findup_or_create.rb
Last active August 29, 2015 14:10
Mongoid find and update, or create
# === Example
# class User
# include Mongoid::Document
# extend FindupOrCreate
#
# field :name, type: String
# field :locale, type: String
# field :password,type: String
# end
#
@xixilive
xixilive / setup_android_keystore.js
Last active May 9, 2016 20:31
Setup Android Keystore after android platform added in Ionic/Cordova project
#!/usr/bin/env node
/**
* Setup android keystore
* Save this script in hooks/after_paltform_add/
* And make sure it has x permission
*/
var exec = require('child_process').exec;
var path = require('path');
@xixilive
xixilive / email_regexp.js
Created June 11, 2015 09:54
Email RegExp from Loopback.io
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
npm install \
--registry=http://registry.npm.taobao.org \
--dist-url=http://npm.taobao.org/mirrors/node \
--build-from-source=v8-profiler\
--phantomjs_cdnurl=http://cnpmjs.org/downloads

微信小程序模块化开发实践

准备

@xixilive
xixilive / weapp-inspector.js
Created January 6, 2017 02:36
wechat applet simulator features inspector
/**
A simple inspector function to detect applet runtime features, such as new functions, new globals etc.
It will report detecting result in the console panel.
*/
const features = {
object: {
assign: true,
is: true,
setPrototypeOf: true,
keys: true,
@xixilive
xixilive / regexp_performance.js
Created September 4, 2018 02:46
Performance testing of a javascript RegExp matching
function strip1(name){
return name.replace(/^(\/*)|(\/*)$/g, '')
}
function strip2(name){
return name.replace(/^(\/+)|(\/+)$/g, '')
}
let str = "///packages/comm/packa/packages/packages/commocomm/packages/"
@xixilive
xixilive / utils.js
Last active March 9, 2019 14:31
utils for node fs
// utitlies module
const path = require('path')
const fs = require('fs')
const noop = () => {}
const debug = process.env.DEBUG ? console.log : noop
// lang functions
const toString = Object.prototype.toString
const typeChecker = (expect) => (val) => toString.call(val) === `[object ${expect}]`
@xixilive
xixilive / createStorageMessageFrame.js
Last active April 10, 2019 06:44
use storage event in iframe
function createStorageMessageFrame(){
const listener ='function(e){window.top.postMessage({key: e.key, oldValue: e.oldValue,newValue: e.newValue}, \''+ window.location.origin +'\')}'
const frame = document.createElement('iframe')
frame.style.width = 0
frame.style.height = 0
frame.style.border = 'none'
frame.style.overflow = 'hidden'
frame.style.visibility = 'hidden'
document.body.appendChild(frame)