Skip to content

Instantly share code, notes, and snippets.

View shenjunru's full-sized avatar

Shen Junru shenjunru

View GitHub Profile
@shenjunru
shenjunru / BROWSERS-DETECT.js
Created September 30, 2012 15:23
javascript: detect browser type by features detection
// IE
// conditional comment
(function(dom){
dom.innerHTML = '<!--[if IE]><br><![endif]-->';
return !!dom.firstChild.tagName;
})(document.createElement('p'));
// Conditional Compilation
// http://msdn.microsoft.com/en-us/library/ahx1z4fs(VS.80).aspx
@shenjunru
shenjunru / build-manifest.php
Created October 6, 2012 05:52
HTML5 Cache Manifest Builder
<?php
/*!
* HTML5 Cache Manifest Builder
* @author Shen Junru
*
* in Command Line:
* - remote=path (ex://domain/path/)
* - path/type=remote (ex: ../js/*.js=/js)
* in Browser:
* - remote=path (ex://domain/path/)
<!DOCTYPE>
<html>
<head>
<title>Center Element by CSS: inline-block</title>
<style type="text/css">
html, body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
@shenjunru
shenjunru / strip_script.js
Last active August 29, 2015 14:15
strip script blocks form html
function strip_script(content, scripts, fix){
var so = 0, ss = 0, se, cs, ce;
var save = Object(scripts) instanceof Array;
while (-1 !== ( ss = content.indexOf('<script', ss) )) {
// update comment range, if it is before the script
while (null == ce || -1 !== ce && ss > ce) {
if (-1 !== ( cs = content.indexOf('<!--', null == ce ? so : ce) )) {
if (-1 === ( ce = content.indexOf('-->', cs) )) {
// fix comment end tag
* {
font-size: 12pt;
font-family: monospace;
font-weight: normal;
font-style: normal;
text-decoration: none;
color: black;
cursor: default;
}

@kangax's ES6 quiz, explained

@kangax created a new interesting quiz, this time devoted to ES6 (aka ES2015). I found this quiz very interesting and quite hard (made myself 3 mistakes on first pass).

Here we go with the explanations:

Question 1:
(function(x, f = () =&gt; x) {
@shenjunru
shenjunru / keybase.md
Created March 4, 2017 13:33
keybase.md

Keybase proof

I hereby claim:

  • I am shenjunru on github.
  • I am shenjunru (https://keybase.io/shenjunru) on keybase.
  • I have a public key whose fingerprint is E3F1 148D 82A1 007E 9266 FDAD 5B97 70CD 0A18 0E3B

To claim this, I am signing this object:

// https://www.textnow.com
// https://www.google.com/voice/?setup=1#setup/
// node >= 8
// usage: node script.js "curl ..."
const https = require('https');
const http = require('http');
const zlib = require('zlib');
const { URL } = require('url');
@shenjunru
shenjunru / node-fs-remove.js
Created May 7, 2018 05:17
node.js remove directory recursively
// remove directory recursively
const { promisify } = require('util');
const $fsys = require('fs');
const $path = require('path');
const fstat = promisify($fsys.stat);
const lsdir = promisify($fsys.readdir);
const mkdir = promisify($fsys.mkdir);
const rmdir = promisify($fsys.rmdir);
const unlink = promisify($fsys.unlink);
@shenjunru
shenjunru / download-realm.sh
Last active March 5, 2019 14:54
download-realm.sh
#!/bin/sh
# file: node_modules/realm/scripts/download-realm.sh
# cwd: node_modules/realm
cd "$(dirname $0)/.."
source ./dependencies.list
VENDOR_DIR="vendor"
LOCKFILE_NAME="download-realm.lock"
NEW_CORE_SERVER_FOLDER="core/v${REALM_CORE_VERSION}"