Skip to content

Instantly share code, notes, and snippets.

View LiuuY's full-sized avatar
💭
👨‍🚀☕️

LiuuY

💭
👨‍🚀☕️
View GitHub Profile
// input string
var originString = [
"st->io",
"io->cond",
"cond(yes)->op1",
"cond(no)->op2",
"op1->sop1",
"op2->sop2",
"sop1->io1",
"sop2->io2",
@LiuuY
LiuuY / getPrimes.js
Created July 22, 2016 06:56
A sieve implementation in JavaScript
// http://stackoverflow.com/a/12287599
function getPrimes(max) {
var sieve = [], i, j, primes = [];
for (i = 2; i <= max; ++i) {
if (!sieve[i]) {
// i has not been marked -- it is prime
primes.push(i);
for (j = i << 1; j <= max; j += i) {
sieve[j] = true;
}
@LiuuY
LiuuY / Package Control.sublime-settings
Last active October 28, 2016 07:57
Sublime Text packages for React.js develop
{
"installed_packages":
[
"Babel",
"EditorConfig",
"Emmet",
"Git",
"HTML-CSS-JS Prettify",
"Oceanic Next Color Scheme",
"Package Control",
@LiuuY
LiuuY / Code Structure
Last active July 29, 2016 07:03
Code Structure
现阶段的代码组织结构是依据代码的类型:
例如action文件夹、pages文件夹等等,但是这样不利于代码的重用,因为一个模块,包含redux相关,css,jsx等等,分布在不同的文件夹里面:
asssets
|- css
|- actions
| - login.js
|- reducers
| - login.js
|- pages
| - login
@LiuuY
LiuuY / arrayInJSX.jsx
Created July 29, 2016 07:17
Array in jsx
// {[...Array(10)].map((x, i) =>
// <div></div>
// )}
var Hello = React.createClass({
getInitialState() {
return {curr: 0}
},
shouldComponentUpdate(nextProps, nextState) {
return !(nextState.curr === this.state.curr)
@LiuuY
LiuuY / validBraces.js
Created July 29, 2016 07:42
Valid Braces
function validBraces(braces){
var matches = { '(':')', '{':'}', '[':']' };
var stack = [];
var currentChar;
for (var i = 0; i < braces.length; i++) {
currentChar = braces[i];
if (matches[currentChar]) { // opening braces
stack.push(currentChar);
/**
* Zebra striped text lines
*/
pre {
padding: .5em;
line-height: 1.5;
background: hsl(20, 50%, 95%);
background-image: linear-gradient(
rgba(120,0,0,.1) 50%, transparent 0);
@LiuuY
LiuuY / index.html
Created September 30, 2016 02:29
Naïve React (no updates 😛) in 60 lines https://twitter.com/dan_abramov/status/781620845185732608
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<div id="root"></div>
</body>

Thanks everyone for participating in the quiz!
Many of you have posted correct answers.

What we know:

A top-level App component returns <Button /> from its render() method.

Question:

>What is the relationship between `` and this in that `Button`’s `render()`?

@LiuuY
LiuuY / Preferences.sublime-settings
Created October 28, 2016 07:59
Sublime Settings
{
"color_scheme": "Packages/User/SublimeLinter/Oceanic Next (SL).tmTheme",
"font_face": "Inziu Iosevka SC",
"font_size": 12,
"ignored_packages":
[
"Vintage"
],
"line_padding_bottom": 1,
"line_padding_top": 1,