This is a short yet insightful article on how to manage “feature branches” when working with Git.

Kaledo Art
he wasn't even looking at me and he found me
One Nice Bug Per Day
Cosmic Funnies
"I'm Dorothy Gale from Kansas"
noise dept.
tumblr dot com


JBB: An Artblog!


blake kathryn
we're not kids anymore.

titsay

⁂
taylor price
dirt enthusiast
i don't do bad sauce passes
AnasAbdin

seen from United States
seen from Türkiye
seen from Maldives
seen from United States

seen from Germany
seen from United States

seen from Malaysia

seen from United Kingdom
seen from United States

seen from Italy
seen from Germany

seen from United States
seen from United States
seen from United States
seen from Spain

seen from United States

seen from United Kingdom

seen from Türkiye

seen from Türkiye
seen from United States
@stuff-select-cool-flatten
This is a short yet insightful article on how to manage “feature branches” when working with Git.

Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
Free to watch • No registration required • HD streaming
It had to be easy to do, and it turns out it actually is.
Isn't it annoying when your editor (or your co-worker's) adds or removes whitespace, making a line seem changed when it really isn't?
Long story short:
git diff -w | git apply --cached --ignore-whitespace
will only add significant changes.
This is one of the best explanations I've found of the differences between Ruby's procs and lambdas, and while I've always favored lambdas because they're stricter, the nice new thing I've just found about procs is that they lend themselves to this syntactic sugar:
u = proc { |id| User.find(id) } u[1] == User.find(1)
Status codes are often overlooked when developing Rails applications, but in order to nicely interact with a non-human user-agent, you should really respond with the appropriate HTTP status code when a POST just failed and you're showing the form again.
Rack::Utils::HTTP_STATUS_CODES is a hash of all the status codes and their descriptions, which can also be used as symbols once downcased and underscored.

Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
Free to watch • No registration required • HD streaming
Reduce the metaprogramming guesswork in your Rails controllers
Metaprogramming is fun and profitable, but as always you have to know the tools of the trade. Many times I've found myself playing with stuff like controller_name.singularize.classify.constantize which is cool when you're following the rules strictly, but breaks horribly if you don't
This tip is no silver bullet against horrible metaprogramming breakages, but it's worth knowing: every ActiveRecord subclass has a method called model_name which gives you a lot of information about its nomenclature at the controller level.
Try for example
User.model_name.param_key User.model_name.route_key User.model_name.collection
and be inspired. ;-)
It turns out it's pretty easy once you know that you have URI.join in your toolset (that was the hard part for me).
Who are you gonna call?
This plugin makes the Rails environment available to the compiler, so that helpers and such can be used. Helped me solve a problem with Refinery CMS through this bug report.
Here's a fairly complete step-by-step guide to setting up your Ruby development environment on a brand new machine. It's useful because I never get the dependencies right at the first try. ;-)
Know your arrays
Every once in a while we stumble in some little known feature of our favorite programming language. Recently I found out about Array#sample: without arguments it picks a random element, with an integer as argument it picks that number of distinct random elements.
(1..6).to_a.sample # => a random number between 1 and 6 (1..6).to_a.sample(6) # => all numbers between 1 and 6, in random order
Isn't that brilliant? ;-)
As a bonus, it's also nice to know about Array#to_set (available once you require 'set'). Often times an array is queried for inclusion of an element with Array#include?, but if you have to do it repeatedly, Set#include? is much faster. There's some overhead in converting the Array to a Set, though, so it's useless (actually slower) for a single check.
require 'benchmark' require 'set' big_num = 1_000_000 big_array = (1..big_num).to_a big_set = big_array.to_set puts Benchmark.measure { 100.times { big_array.include?(big_num) } } puts Benchmark.measure { 100.times { big_set.include?(big_num) } }
will output
12.940000 0.030000 12.970000 ( 13.308623) 0.000000 0.000000 0.000000 ( 0.000048)

Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
Free to watch • No registration required • HD streaming
Instead of writing the same controller code over and over, we can choose to let the router do most of the dirty work in a declarative fashion, and then delegate to a class that does the actual work once all conditions have been met. Here's an interesting example.
Test-driven development is great, but writing good tests is even better for your sanity. Here are some common pitfalls and some excellent suggestions.
Rails teaches you how to be a better programmer if you come from PHP, but the truth is that there's always room for improvement. The longer you stick to Rails' "best practices" the fatter and messier your models get. Here are some patterns to make them slender and elegant again.
Sometimes, especially when working on the console, you just want a quick and dirty way to instantiate an object from a hash without having to go through all the (justified!) paranoia of mass-assignment protection. In a nutshell, here's how:
user.assign_attributes({ :name => 'Josh', :is_admin => true }, :without_protection => true)
Working with multiple databases in Rails
Ever had to work with your application's schema and a legacy schema simultaneously? Rails has you covered: not only can you have per-class database connections, but it's actually easy to do. All you have to do is to declare an additional section in your config/database.yml like this:
development: adapter: sqlite3 database: db/development.sqlite3 legacy: adapter: 'mysql2' database: 'legacy' username: 'legacy_user' password: 'super_secret_password'
and then you'll be able to use the database connection in any model by declaring which connection to use:
class LegacyUser < ActiveRecord::Base establish_connection :legacy end
Of course to make things DRYer you can also declare an abstract class, say LegacyModel, put the connection declaration there, and make all the other legacy classes inherit from there.
Pretty neat, but what if the two schemas are identical and you want to access both with a minumum of fuss? Lets's say you want to programmatically transfer a sample of data from production to testing with the console (be careful!) or you want to mess around in the testing database without risking to break development. Looks like a nice job for metaprogramming, doesn't it? So here we go:
module Legacy def self.const_missing(name) if Object.const_defined?(name) klass = Class.new("::#{name}".constantize) klass.establish_connection :legacy return klass end super end end
This nice snippet of code (which we'll save in app/models/legacy.rb to help the autoloader do its job) is really all it takes to duplicate all models (actually, any class) in the Legacy:: namespace and to change the database connection to the one defined in the configuration file. This way, User will point to the current environment's users database table, but with the appropriate changes, Production::User could point to the users on the production server.
The code is the bare working minimum for the sake of simplicity, but it can easily be improved by a check for the availability of the establish_connection method in order to throw the right exception if we're duplicating, say, a controller by mistake. But since this class isn't really meant to go into production (there are security issues to be addressed as well), I guess it's okay if you just want to move some data from one database to another with a finer granularity and better abstraction than a database dump would allow.

Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
Free to watch • No registration required • HD streaming