@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:
(function(x, f = () => x) {
var fs = require('fs') | |
var trie = {} | |
var tempWords = {}; | |
fs.readFile('./text.txt',function(err,callback){ | |
var str = callback.toString(); | |
str = str.replace(/[^\u4e00-\u9fa5]/g,'@'); | |
str = str.replace(/@+/g,' ') | |
split(str); |
var fs = require('fs'), | |
crypto = require('crypto'); | |
var key = '14189dc35ae35e75ff31d7502e245cd9bc7803838fbfd5c773cdcd79b8a28bbd', | |
cipher = crypto.createCipher('aes-256-cbc', key); | |
input = fs.createReadStream('test.txt'), | |
output = fs.createWriteStream('test.txt.enc'); | |
input.pipe(cipher).pipe(output); |
<?php | |
$localfile = "test.mp4"; | |
$size = filesize($localfile); | |
$start = 0; | |
$end = $size - 1; | |
$length = $size; | |
header("Accept-Ranges: 0-$size"); |
#!/usr/bin/env node | |
var fs = require('fs'); | |
var http = require('http'); | |
var request = require('request'); | |
var urlListFile = 'url.list'; | |
if (!fs.existsSync(urlListFile)) { |
#! /bin/sh | |
### BEGIN INIT INFO | |
# Provides: supervisord | |
# Required-Start: $remote_fs | |
# Required-Stop: $remote_fs | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: Example initscript | |
# Description: This file should be used to construct scripts to be | |
# placed in /etc/init.d. |
// for demo: http://jsbin.com/jeqesisa/7/edit | |
// for detailed comments, see my SO answer here http://stackoverflow.com/questions/8853396/logical-operator-in-a-handlebars-js-if-conditional/21915381#21915381 | |
/* a helper to execute an IF statement with any expression | |
USAGE: | |
-- Yes you NEED to properly escape the string literals, or just alternate single and double quotes | |
-- to access any global function or property you should use window.functionName() instead of just functionName() | |
-- this example assumes you passed this context to your handlebars template( {name: 'Sam', age: '20' } ), notice age is a string, just for so I can demo parseInt later | |
<p> | |
{{#xif " this.name == 'Sam' && this.age === '12' " }} |
@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:
(function(x, f = () => x) {
<!DOCTYPE html> <!-- HTML5 doctype 不区分大小写 --> | |
<html lang="zh-cmn-Hans-CN"> <!-- 更加标准的 lang 属性写法 http://zhi.hu/XyIa --> | |
<head> | |
<meta charset="UTF-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> <!-- 优先使用IE最新版本和 Chrome --> | |
<meta name="renderer" content="webkit|ie-comp|ie-stand"> <!-- 360 浏览器内核控制 --> | |
<!-- | |
content的取值为webkit,ie-comp,ie-stand之一,区分大小写,分别代表用webkit内核,IE兼容内核,IE标准内核。 |