This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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" && ( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm install style-loader css-loader node-sass sass-loader extract-text-webpack-plugin@1.0.1 --save |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# rubocop version 0.52.1 | |
# bundle exec rubocop -a -D -S | |
# disable all cops example | |
# rubocop:disable all | |
# rubocop:enable all | |
AllCops: | |
Include: | |
- Rakefile |