Skip to content

Instantly share code, notes, and snippets.

@roshanca
roshanca / map-vs-flatmap.js
Created January 22, 2017 04:58 — forked from ruanyf/map-vs-flatmap.js
map vs. flatMap
const map = (array, func) => (
array.map(func)
);
const flatMap = (array, func) => (
array.reduce((result, element) => (
result.concat(func(element))
), [])
);
@roshanca
roshanca / jQuery-plugin-authoring.md
Created August 14, 2016 02:41 — forked from quexer/jQuery-plugin-authoring.md
如何编写 jQuery 插件

创建插件


看来 jQuery 你已经用得很爽了,想学习如何自己编写插件。非常好,这篇文档正适合你。用插件和方法来扩展 jQuery 非常强大,把最聪明的功能封装到插件中可以为你及团队节省大量开发时间。

开始

@roshanca
roshanca / loading.ts
Created November 24, 2015 15:18 — forked from pdib/loading.ts
Create a loading spinner that disappears once the content is loaded with Angular 2.
@Component({
selector: 'spinner',
template: `<h1>spinner</h1>` // This will be displayed while loading.
})
class Spinner {
}
@Directive({
selector: "[loading]",
inputs: ["loading"],
@roshanca
roshanca / gist:17a43778c7e03ef33959
Created November 19, 2015 05:10 — forked from Steven-Rose/gist:3943830
VI: Select all + delete, select all + copy
Select all and delete (actually move to buffer)
:%d
Select all and copy to buffer
:%y
Use p to paste the buffer.
@roshanca
roshanca / angularjs-providers-explained.md
Last active August 29, 2015 14:27 — forked from demisx/angularjs-providers-explained.md
AngularJS Providers: Constant/Value/Service/Factory/Decorator/Provider
Provider Singleton Instantiable Configurable
Constant Yes No No
Value Yes No No
Service Yes No No
Factory Yes Yes No
Decorator Yes No? No
Provider Yes Yes Yes

Constant

Fixing npm On Mac OS X for Homebrew Users

If you just want to fix the issue quickly, scroll down to the "solution" section below.

Explanation of the issue

If you're a Homebrew user and you installed node via Homebrew, there is a major philosophical issue with the way Homebrew and NPM work together. If you install node with Homebrew and then try to do npm update npm -g, you may see an error like this:

$ npm update npm -g

Problem

  • Using emmet in jsx files
  • Emmet expands text when js autocomplete needed
  • Using className instead of class

How it works

  • Install plugin RegReplace
  • Install plugin Chain Of Command
FROM ubuntu:14.04
MAINTAINER Pan Jiabang, panjiabang@gmail.com
RUN \
# use aliyun's mirror for better download speed
sed -i 's/archive.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list && \
apt-get update && \
apt-get install -y nodejs curl git-core && \
# use nodejs as node
@roshanca
roshanca / Makefile
Last active August 29, 2015 14:14 — forked from bpierre/Makefile
# JS files
JS_FINAL = js/project-name-all.js
JS_TARGETS = js/file1.js \
js/file2.js \
js/file3.js
# CSS files
CSS_FINAL = css/project-name-all.css
STYLUS_TARGETS = css/file1.styl \
_.mixin({
// This will parse a delimited string into an array of
// arrays. The default delimiter is the comma, but this
// can be overriden in the second argument.
CSVtoJSON: function( strData, strDelimiter ){
// Check to see if the delimiter is defined. If not,
// then default to comma.
strDelimiter = (strDelimiter || ",");
// FIX: add an ending carriage return if missing