Skip to content

Instantly share code, notes, and snippets.

View cheeyeo's full-sized avatar
💭
Researching on use of transformers in computer vision

Chee Yeo cheeyeo

💭
Researching on use of transformers in computer vision
View GitHub Profile
@cheeyeo
cheeyeo / pipe.exs
Created July 21, 2015 22:05
Inspecting using pipe operator in Elixir
[1,2,3] |> Enum.map(&(IO.inspect(&1)))

React.js Minimal Entropy Guide

DO's:

  • Use explicit contracts to pipe data & events between systems
  • Business rules should bubble towards the top, UI and semantics should sink towards the bottom

DONT's:

@cheeyeo
cheeyeo / example.js
Last active August 29, 2015 14:24
REACTJS
// calling setProps is not good practice
// instead render the component outside of the react loop
React.render(
myComponent({ data: someData2 }),
document.getElementById('predictionContent')
);
@cheeyeo
cheeyeo / gist:c7a75b26c1ee5b96f4ea
Created June 17, 2015 15:17
Ruby Rails security list
https://groups.google.com/forum/#!forum/rubyonrails-security
defmodule MacroExp do
defmacro attr_accessor(atom) do
getter = String.to_atom("get_#{atom}")
setter = String.to_atom("set_#{atom}")
quote do
def unquote(getter)(data) do
data |> Map.from_struct |> Map.get(unquote(atom))
end
def unquote(setter)(data, value) do
data |> Map.put(unquote(atom), value)
items = %w{foo bar baz goo gar gaz hoo har haz}
def recurse_array(ary, &block)
head, *tail = ary
head and block.call(head)
tail.any? and recurse_array(tail, &block)
end
puts "First the items in order:\n"
recurse_array items do |item|
# Call scopes directly from your URL params:
#
# @products = Product.filter(params.slice(:status, :location, :starts_with))
module Filterable
extend ActiveSupport::Concern
module ClassMethods
# Call the class methods with the same name as the keys in <tt>filtering_params</tt>
# with their associated values. Most useful for calling named scopes from
@cheeyeo
cheeyeo / sample.rb
Created April 1, 2015 22:24
accepts_nested_attributes
# http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html
# need to specify id for an update:
class Member < ActiveRecord::Base
has_one :avatar
accepts_nested_attributes_for :avatar
end
params = { member: { name: 'Jack', avatar_attributes: { icon: 'smiling' } } }