- Don’t repeat yourself
- Control method length
- Be careful how you fix what you don’t understand
- Frederick P. Brooks
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
# Define a free function with the same name as a class (returns the class and the args passed to the function, the constructor data) | |
def javascriptenator( klass ) | |
Kernel.send( :define_method, klass.name.to_sym ) { |*args| return [klass,args] } | |
end | |
# Parameter is the return from the class-named function. Use class name to create object and pass constructor data. | |
def new( class_and_args ) | |
class_and_args.first.new( *class_and_args.last ) | |
end |
I hereby claim:
- I am TeknoFiend on github.
- I am teknofiend (https://keybase.io/teknofiend) on keybase.
- I have a public key whose fingerprint is 940A 1BF8 10CD AC35 6768 B3AD 59F6 7675 F405 FA22
To claim this, I am signing this object:
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
<%# Making sure a Rails partial's dependencies are represented in the cache keys is a common source %> | |
<%# of bugs that are hard to debug & often "bad" (revealing priviledged info). %> | |
<%# One strategy I've used is to cache outside a partial and try to pass the parts of the cache %> | |
<%# key to the partial as locals. This setup is beneficial because the proximity of the key to %> | |
<%# the locals makes it easier to realize/remember to update them at the same time. But they can %> | |
<%# still fall out of sync (also the partial can access `@post` or whatever behind your back). %> | |
<% cache [ @post, @user.can_edit?, @user.can_delete? ] do %> |
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
////////////////////////////////////////////////////////////////////// | |
// Proposal for doing in-template (JSX) conditions. This can be done | |
// with components (e.g. https://www.npmjs.com/package/react-if) but | |
// I think the cognitive separation of logic & markup is important. | |
// It feels a little less noisy to me too. | |
// | |
// Naming, code-style & even some of the intra-JS semantics could be | |
// changed but this shows off what's possible. Style-wise I like | |
// having the `then` (vs not as in the `case` example), and I like | |
// the inline style used for `elsif` over the stacked style used |