Skip to content

Instantly share code, notes, and snippets.

View wangshijun's full-sized avatar

wangshijun wangshijun

View GitHub Profile
@getify
getify / gist:3667624
Last active June 25, 2022 16:26
escape all (not-already-escaped) double-quote chars in a string
// NOTE: only escapes a " if it's not already escaped
function escapeDoubleQuotes(str) {
return str.replace(/\\([\s\S])|(")/g,"\\$1$2"); // thanks @slevithan!
}
escapeDoubleQuotes(`ab`); // ab => ab (nothing escaped)
escapeDoubleQuotes(`a"b`); // a"b => a\"b
escapeDoubleQuotes(`a\\"b`); // a\"b => a\"b (nothing escaped)
escapeDoubleQuotes(`a\\\\"b`); // a\\"b => a\\\"b
escapeDoubleQuotes(`a\\\\\\"b`); // a\\\"b => a\\\"b (nothing escaped)
@agnoster
agnoster / README.md
Last active April 6, 2024 22:35
My ZSH Theme

agnoster.zsh-theme

A ZSH theme optimized for people who use:

  • Solarized
  • Git
  • Unicode-compatible fonts and terminals (I use iTerm2 + Menlo)

For Mac users, I highly recommend iTerm 2 + Solarized Dark

@amoilanen
amoilanen / webcrawler.js
Last active March 24, 2022 03:14
Simple PhantomJS-based web crawler library
//PhantomJS http://phantomjs.org/ based web crawler Anton Ivanov anton.al.ivanov@gmail.com 2012
//UPDATE: This gist has been made into a Node.js module and now can be installed with "npm install js-crawler"
//the Node.js version does not use Phantom.JS, but the API available to the client is similar to the present gist
(function(host) {
function Crawler() {
this.visitedURLs = {};
};
@mbostock
mbostock / .block
Last active June 1, 2021 21:40 — forked from mbostock/.block
Multi-Series Line Chart
license: gpl-3.0
redirect: https://beta.observablehq.com/@mbostock/d3-multi-line-chart
@Kapeli
Kapeli / gist:5017177
Created February 22, 2013 22:43 — forked from yjsoon/gist:3474117
" Search Dash for word under cursor
function! SearchDash()
let s:browser = "/usr/bin/open"
let s:wordUnderCursor = expand("<cword>")
let s:url = "dash://".s:wordUnderCursor
let s:cmd ="silent ! " . s:browser . " " . s:url
execute s:cmd
redraw!
endfunction
map <leader>d :call SearchDash()<CR>
@johnnyelwailer
johnnyelwailer / keyboard_navigation_service.js
Last active July 6, 2016 10:47
keyboard navigation directive / service in angular js (depends on jq and rxjs)
angular.module('keyboard', [])
.factory('keyboardNavigation', function () {
var keyboardContextStack = [];
var navigatables = {};
var activeIndex = 0;
return {
active: null,
register: function (scope, events) {
@gnarf
gnarf / ..git-pr.md
Last active April 12, 2024 22:00
git pr - Global .gitconfig aliases for Pull Request Managment

Install

Either copy the aliases from the .gitconfig or run the commands in add-pr-alias.sh

Usage

Easily checkout local copies of pull requests from remotes:

  • git pr 4 - creates local branch pr/4 from the github upstream(if it exists) or origin remote and checks it out
  • git pr 4 someremote - creates local branch pr/4 from someremote remote and checks it out
@outmost
outmost / node_beacon.js
Last active December 17, 2015 01:58
Node JS beacon to capture performance metrics from Boomerang.
// Assumptions
// Boomerang makes beacon call to port :8080
// StatsD is running on same server (localhost)
// The following NodeJS modules are installed:
// https://github.com/tobie/ua-parser
// https://github.com/bluesmoon/node-geoip
// Boomerang is configured to send custom parameters for "domain", "page_type", "user_status", "ip" and "user_agent".
// http://lognormal.github.io/boomerang/doc/howtos/howto-5.html
@johann8384
johann8384 / create_table.rb
Last active October 30, 2017 03:23
Creating Tables for OpenTSDB
# usage: ./create_table.rb tsdb 255
include Java
import org.apache.hadoop.hbase.HBaseConfiguration
import org.apache.hadoop.hbase.HTableDescriptor
import org.apache.hadoop.hbase.client.HBaseAdmin
import org.apache.hadoop.hbase.HColumnDescriptor
conf = HBaseConfiguration.create
conf.set("zookeeper.znode.parent", "/hbase-unsecure");
@icflorescu
icflorescu / app.coffee
Last active April 20, 2016 02:15
Complex routing with express.js + CoffeeScript
###
It's incredibly easy to set-up a complex, SEO-friendly routing system using
the powerful CoffeeScript regular expressions and destructuring assignment syntax (to parse/name route parameters).
For instance, the code snippet below will respond to routes like:
/offers/category-automobiles
/offers/category-automobiles/make-alfa-romeo
/offers/category-automobiles/make-alfa-romeo/model-159