Skip to content

Instantly share code, notes, and snippets.

View syntacticsugar's full-sized avatar
🎯
Focusing

RomyRomy syntacticsugar

🎯
Focusing
View GitHub Profile
const counter = (state=0, action) => {
switch (action.type) {
case 'INCREMENT':
return state + 1;
case 'DECREMENT':
return state - 1;
default:
return state;
}
}
@syntacticsugar
syntacticsugar / es6_destructuring_assignment.js
Created June 13, 2016 16:41
The destructuring assignment syntax is a JavaScript expression that makes it possible to extract data from arrays or objects into distinct variables.
var a, b, rest;
[a,b] = [1,2];
console.log(a); // 1
console.log(b); // 2 // wow, so convenient! will I remember to do this, or not bother?
[a, b, ...rest] = [1, 2, 3, 4, 5];
console.log(a); // 1
console.log(b); // 2
console.log(rest); // [3, 4, 5] // incredible... although now I'm thinking this is nearly illegible for other developers
/**
* Trapezoid tabs
*/
body {
padding: 40px;
font: 130%/2 Frutiger LT Std, sans-serif;
}
nav {
@syntacticsugar
syntacticsugar / tweetbox.jsx
Created February 17, 2016 03:01
yet another review of <TweetBox />
var TweetBox = React.createClass({
getInitialState: function() {
return {
text: "",
photoAdded : false,
};
},
togglePhoto : function(event) {
this.setState({ photoAdded: !this.state.photoAdded })
},
@syntacticsugar
syntacticsugar / defining_lists.elm
Created March 16, 2015 03:05
wherein we try defining `list`
import Text (asText)
type Collection a = Nada | Glue a (Collection a)
summm xs =
case xs of
Nada -> 0
Glue face body -> face + (summm body)
listToCollection collection =
module Sinatra
module Kittens
module Helpers
def kittens_page(x = 200..500, factor = 0.2)
sample_method = RUBY_VERSION >= '1.9' ? :sample : :choice
x = x.to_a.send(sample_method)
y = ((x - factor*x).floor..(x + factor*x).ceil).to_a.send(sample_method)
<<-HTML
<!DOCTYPE html>
@syntacticsugar
syntacticsugar / js_recursion_simple.js
Created October 6, 2014 16:14
A simple JS recursion using slice.
function sum (numbers) {
return !numbers.length ? 0 : numbers[0] + sum(numbers.slice(1));
};
@syntacticsugar
syntacticsugar / maybe.sml
Created September 17, 2014 22:09
tutorial from Nicky Bicky
type Maybe a = Nothing | Just a
type Option a = None | Some a
type Result a = Failure | Success a
max [] ----> Failure
max [1,2,3] -----> Success 3
textarea:focus,
input[type="text"]:focus,
input[type="password"]:focus,
input[type="datetime"]:focus,
input[type="datetime-local"]:focus,
input[type="date"]:focus,
input[type="month"]:focus,
input[type="time"]:focus,
input[type="week"]:focus,
input[type="number"]:focus,
class GuessTheNumber
def play
@nnn = 1.upto(100).to_a.sample
# play game
puts "Alright, I have a number in mind from 1-100. Pick a number."
guess = gets.chomp
puts "You said #{guess}."
attempt guess
end