This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Let's say you want a text field on a webpage | |
// where the user can enter a mix of comma delimited, | |
// white space delimited and line delimited. | |
// | |
// BUT you want the computer to read it as a flat list | |
var str = "1,2\n3 4"; | |
str.replace(/,\W/g, ' ') | |
.replace(/,/g, ' ') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
class NameList extends React.Component { | |
constructor(props){ | |
super(props); | |
} | |
render() { | |
var i = 1; | |
var list = this.props.names.map( (name) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Makefile for web development with: | |
# 1. ES6 / Babel compiler | |
# setup: npm install babel | |
# 2. Bundler (Webpack or Browserify) | |
# setup: npm install webpack|browserify | |
# 3. Static Web Server | |
# setup: npm install http-server | |
WEBMAKE = webmake | |
WEBPACK = webpack |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<html> | |
<head> | |
<title>Minimal React Setup</title> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.3/react.min.js" type="text/javascript"></script> | |
</head> | |
<body> | |
<script src="app.js" type="text/javascript"></script> | |
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var time = 1000; | |
function updateTimer() { | |
document.body.innerHTML = ('<div style="font-size: 6em">' + Math.round(time/60) + ":" + (--time%60) + '</div><br/><div>' + time + ' total seconds</div>') | |
} | |
var timerId = setInterval( updateTimer, 1000) | |
// reset with: | |
// clearInterval(timerId); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[1,1,2,2,3,3,4,4,5].reduce( function(a, b, i) { | |
if (i === 1) { | |
return [[a, b]]; | |
} else { | |
if (i % 2 === 0) { | |
return a.concat([[b]]); | |
} else { | |
return a.splice(0, a.length-1).concat([a[a.length-1].concat(b)]); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[]['map']['constructor']('s', 'alert(s); return true')('You don\'t know JavaScript') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%s/var \(.*\) = require('\(.*\)');/import \1 from '\2'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let a = 1, b = 2, foo="foo", bar="bar", credentials: "insecure"; | |
String.raw`http://foo.org/bar?a=${a}&b=${b} | |
Content-Type: application/json | |
X-Credentials: ${credentials} | |
{ "foo": ${foo}, | |
"bar": ${bar}}`; | |
/* The code above produces the result | |
"http://foo.org/bar?a=1&b=2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* description: Parses end executes mathematical expressions. */ | |
/* lexical grammar */ | |
%lex | |
%% | |
\s+ /* skip whitespace */ | |
[0-9]+("."[0-9]+)?\b return 'NUMBER' | |
"true" return 'TRUE' | |
"false" return 'FALSE' |
OlderNewer