Skip to content

Instantly share code, notes, and snippets.

View PeterRao's full-sized avatar

Undefined PeterRao

  • 北京
View GitHub Profile
var serialAsyncMap = function () {
var _ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee(collection, fn) {
var result, _iterator, _isArray, _i, _ref2, item;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
result = [];
_iterator = collection, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Virtual Template Example</title>
</head>
<body>
</body>
@PeterRao
PeterRao / pub-sub.js
Last active February 1, 2016 12:07
发布订阅模式,支持事件先发布
var Event = (function() {
var global = this,
Event,
_default = 'default';
Event = function() {
var _listen,
_trigger,
_remove,
@PeterRao
PeterRao / urlparser.js
Last active August 29, 2015 14:11 — forked from sofish/urlparser.js
var parser = function(url) {
var a = document.createElement('a');
a.href = url;
var search = function(search) {
if(!search) return {};
var ret = {};
search = search.slice(1).split('&');
for(var i = 0, arr; i < search.length; i++) {
@PeterRao
PeterRao / judgeINIframe
Last active August 29, 2015 14:05
How to judge whether 1 JS in iframe(http://www.programering.com/a/MDOwMzMwATg.html)
//One way
if (self.frameElement && self.frameElement.tagName == "IFRAME") {
alert('In iframe');
}
//Methods two
if (window.frames.length != parent.frames.length) {
alert('In iframe');
}
//Fang Shisan
if (self != top) {

This Is Absolutely Tiring

Every time I start a node module, or a new JS project, I'm confronted with this same question: how do I structure it to allow it to be used in the browser or nodejs, without requiring a build step, and without getting in the way of my development?

While developing, I typically create some type of [browser-based environment][]; Firebug and Web Inspector are still miles ahead of anything else we've got. Ideally I want to be able to add a file via a script tag, and have that be the only requirement.

As @visionmedia [points out][], this is [ridiculous][].

This gist is meant to compile all of the various ways I've seen of guarding against/for a variety of module systems. Fork it and add your own, I'll try to bring them into this one.

@PeterRao
PeterRao / first.js
Created March 27, 2014 10:46 — forked from sofish/first.js
// 大家写在评论中吧,代码高亮可以这样写:
// ```js
// your code
// ```
// update: Fri Aug 31 08:39:21
// copyright: https://gist.github.com/3549352
// 加个性能测试:http://jsperf.com/get-dom-s-first-element
var util = {};
@PeterRao
PeterRao / .jshintrc
Created March 3, 2014 03:04
JSHint 文件
{
// JSHint Default Configuration File (as on JSHint website)
// See http://jshint.com/docs/ for more details
"maxerr" : 100, // {int} Maximum error before stopping
// Enforcing
"bitwise" : true, // true: Prohibit bitwise operators (&, |, ^, etc.)
"camelcase" : true, // true: Identifiers must be in camelCase
"curly" : true, // true: Require {} for every new block or scope
@PeterRao
PeterRao / getQueryStringRegExp.js
Created December 31, 2013 01:28
jS:获取URL参数
function getQueryStringRegExp(name) {
var reg = new RegExp("(^|\\?|&)"+ name +"=([^&]*)(\\s|&|$)", "i");
if (reg.test(location.href)) {
return unescape(RegExp.$2.replace(/\+/g, " "));
}
return "";
}
@PeterRao
PeterRao / rails_resources.md
Created December 14, 2013 10:27 — forked from jookyboi/rails_resources.md
Rails-related Gems and guides to accelerate your web project.

Gems

  • Bundler - Bundler maintains a consistent environment for ruby applications. It tracks an application's code and the rubygems it needs to run, so that an application will always have the exact gems (and versions) that it needs to run.
  • rabl - General ruby templating with json, bson, xml, plist and msgpack support
  • Thin - Very fast and lightweight Ruby web server
  • Unicorn - Unicorn is an HTTP server for Rack applications designed to only serve fast clients on low-latency, high-bandwidth connections and take advantage of features in Unix/Unix-like kernels.
  • SimpleCov - SimpleCov is a code coverage analysis tool for Ruby 1.9.
  • Zeus - Zeus preloads your Rails app so that your normal development tasks such as console, server, generate, and specs/tests take less than one second.
  • [factory_girl](h