Skip to content

Instantly share code, notes, and snippets.

View roberto's full-sized avatar
🍊

Roberto Soares roberto

🍊
View GitHub Profile
@roberto
roberto / _flash_messages.html.erb
Created August 13, 2012 22:47
Rails flash messages using Twitter Bootstrap
<% flash.each do |type, message| %>
<div class="alert <%= bootstrap_class_for(type) %> fade in">
<button class="close" data-dismiss="alert">×</button>
<%= message %>
</div>
<% end %>
class ArticlesController < ApplicationController
before_filter :load_temp_upload, :only => ["create", "update"]
def update
if params[:ajaxupload]
if @article.update_attributes(:picture => params[:article][:picture])
render(:text => {:response => 'success', :url => @article.picture.url(:thumb)}.to_json)
else
render(:text => {:response => 'failure', :message => @article.errors.full_messages.join('\n')}.to_json)
end
const setJackson = R.pipe(
R.prop("users"),
R.map(
(user) =>
R.startsWith('J', user.name)
? {...user, name: R.concat(user.name, ' Jackson')}
: user
)
)
const isOld = R.gt(R.__, 33)
const getOldPeople = R.pipe(
R.prop("users"),
R.filter(R.where({age: isOld}))
)
const getOldPeople = R.pipe(
R.prop("users"),
R.filter(R.propSatisfies(isOld, 'age'))
R.pipe(
R.prop("users"),
R.sortBy(R.prop("age")),
R.take(3),
R.pluck("name")
)
@roberto
roberto / myProp.js
Last active January 24, 2018 22:55
Currying - Simple
const myProp = (key, maybeObject) => {
if (maybeObject === undefined) {
return (object) => {
return myProp(key, object)
}
}
return maybeObject[key]
}
const increment = (key, obj) => {
return {
...obj,
[key]: obj[key] + 1
}
}

10 weird tricks that React developers near you are using to create reusable components

https://www.youtube.com/watch?v=nQo0EdHNjto

  • reusable components
    • props over state
      • prop === state => problem!
    • stateless components
    • easy to unit test
  • PropTypes are serious
import Html exposing (text)
partition n =
break (n - 1, 0)
break (n, total) =
case n of
1 -> total + 1
n -> 1 + break(n - 1, total + 1)

Blazing fast:

emacs --daemon
emacsclient .

inside terminal:

emacsclient -nw .