Skip to content

Instantly share code, notes, and snippets.

View MiguelSavignano's full-sized avatar

Miguel Savignano MiguelSavignano

View GitHub Profile
@MiguelSavignano
MiguelSavignano / es_next.js
Created March 19, 2017 00:20
Test new features in javascript
function printArguments(target, name, descriptor) {
let oldFunction = descriptor.value
descriptor.value = function () {
console.log(`start ${name} with arguments`, arguments)
oldFunction.apply(target, arguments)
console.log(`end function ${name}`)
}
return descriptor
//if else in jsx
//we need to render the tab view if the tab it's active, and loop the users if not users show empty message
//option 1
render(){
const {users, tab_active} = this.state
return (
<div>
{ tab_active == "users" && (
@MiguelSavignano
MiguelSavignano / base.rb
Created April 3, 2017 13:34
add mongoid base for share methods
#models/concersns/mongoid/base.rb
module Mongoid::Base
extend ActiveSupport::Concern
include Mongoid::Timestamps
module ClassMethods
def random
self.skip(rand(self.count)).first
end
npm install style-loader css-loader node-sass sass-loader extract-text-webpack-plugin@1.0.1 --save
//styled componet with multiple values depending on prop name
const Avatar = styled.img`
height: ${ ({size, theme}) => theme.size[size] };
width: ${ ({size, theme}) => theme.size[size] };
`;
Avatar.defaultProps = {
size: "small",
theme: {
size:{
small: "50px",
@MiguelSavignano
MiguelSavignano / mongoid_serialize_id.rb
Last active June 15, 2017 13:22
normalize the id field with mongoid
# before
#MyModel.as_json => {name:"Awesome", _id: {$oid{ "asd488asd78as"}}
# after
#MyModel.as_json => {name:"Awesome", id:"asd488asd78as"}
# https://stackoverflow.com/questions/23505247/have-to-json-return-a-mongoid-as-a-string
module BSON
class ObjectId
def to_json(*)
to_s.to_json
@MiguelSavignano
MiguelSavignano / react_component_styled.rb
Last active June 29, 2017 18:10
Styled Component server side rendering with React on Rails
def react_component_styled(component_name, props: {})
random_id = "react-#{component_name}--#{SecureRandom.uuid}"
ReactOnRails::ServerRenderingPool.reset_pool_if_server_bundle_was_modified
js_code = "ReactOnRails.getHtmlAndCss('#{component_name}', #{props.to_json})"
result = ReactOnRails::ServerRenderingPool.eval_js(js_code) || {}
"
#{ result['css'] if result['css'] }
<div id='#{random_id}'>#{result['html']}</div>
<script>
(function(){
// webpack-register.js
class WebpackRegister {
deleteFileExtension = (file_name = "") => file_name.substr(0, file_name.lastIndexOf('.')) || file_name
getAllModulesByFile = (requireContext, prefix = "") => {
const files_paths = requireContext.keys();
return files_paths.map((file_path) => {
const object = {}
const id = requireContext.resolve(file_path)
@MiguelSavignano
MiguelSavignano / hash.rb
Created December 29, 2017 21:31
ruby hash with indiferent access
# my_hash = { "foo": "bazz", foo2: "bazz2" }
# my_hash.foo # "bazz"
# my_hash.foo2 # "bazz2"
class Hash
def method_missing(method, *opts)
method = method.to_s
if self.has_key?(method)
return self[method]
elsif self.has_key?(method.to_sym)
return self[method.to_sym]
# rubocop version 0.52.1
# bundle exec rubocop -a -D -S
# disable all cops example
# rubocop:disable all
# rubocop:enable all
AllCops:
Include:
- Rakefile