Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

RomyRomy syntacticsugar

🎯
Focusing
View GitHub Profile
View es6_redux_destructure_import.js
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 Jun 13, 2016
The destructuring assignment syntax is a JavaScript expression that makes it possible to extract data from arrays or objects into distinct variables.
View es6_destructuring_assignment.js
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
View trapezoid.css
/**
* Trapezoid tabs
*/
body {
padding: 40px;
font: 130%/2 Frutiger LT Std, sans-serif;
}
nav {
@syntacticsugar
syntacticsugar / tweetbox.jsx
Created Feb 17, 2016
yet another review of <TweetBox />
View tweetbox.jsx
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 Mar 16, 2015
wherein we try defining `list`
View defining_lists.elm
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 =
View helpers.rb
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 Oct 6, 2014
A simple JS recursion using slice.
View js_recursion_simple.js
function sum (numbers) {
return !numbers.length ? 0 : numbers[0] + sum(numbers.slice(1));
};
@syntacticsugar
syntacticsugar / maybe.sml
Created Sep 17, 2014
tutorial from Nicky Bicky
View maybe.sml
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
View bootstrap_form_override.css
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,
View guess_the_number.rb
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