How to get the hostname of the current machine in Rails or a Ruby script
Use Socket.gethostname. So for a machine whose hostname is "happycat", it will look like this:
>> Socket.gethostname
=> "happycat"
That should work right away for your Rails application. For plain Ruby, you first need to do:
require 'socket'
If you don't want to use Socket for some reason, you can still just use the hostname command, at least on non-Windows machines. Keep in mind that you need to remove trailing white space from the result of the system call.
>> `hostname`
=> "happycat\n"
>> `hostname`.stri...
Consul 0.5.0 is faster for admins, allows to define multiple powers at once
When calling a scope like current_power.user?(user), Consul will no longer trigger a query if the users power selects all records (SELECT * from users). This should make such checks much faster for users who can access many records, like admins.
You can now define multiple powers at once:
power :users, :updatable_users, :creatable_users do
...
end
Customize tokenization of the MySQL FULLTEXT parser
The way MySQL's FULLTEXT tokenizer splits text into word tokens might not always be what you need. E.g. it splits a word at period characters.
Since the tokenizer has near-zero configuration options (minimum word length and stopwords list), you need to hack it. There are three options available.
Option 1: If you like pain
Write a Full-Text parser plugin in C.
Option 2: Make the problem go away
Normaliz...
Fix error: undefined method `desc' for #<Foo::Rake::Taskx1234>
Upgrade the offending gem. If you cannot or don't want to upgrade, lock rake to 0.8.7.
Fix warning: No secret option provided to Rack::Session::Cookie
You will get this when you are using the latest version of Rails with a recent version of Rack:
SECURITY WARNING: No secret option provided to Rack::Session::Cookie.
This poses a security threat. It is strongly recommended that you
provide a secret to prevent exploits that may be possible from crafted
cookies. This will not be supported in future versions of Rack, and
future versions will even invalidate your existing user cookies.
The warning is caused by Rails calling Rack incorrectly. [It is unclear](https://github.c...
Mac: Turn applications to Full Screen mode from bash
I needed a way to make my apps full screen from bash scripts. There is no super-easy way, but it's not too hard either.
Put the attached script into e.g. /usr/local/bin and make it executable. Now you can call
fullscreen Safari
and Safari will go full screen.
Notes
- This script needs activated access for assisting devices. Turn it on with
osascript -e 'tell application "System Events" to set UI elements enabled to true'. - The capitalization of the application name is important, i.e. it's
TextMateand nottextmate. - ...
CSS Explain - A tool which calculates CSS selector specificity
Example input:
li.active a:link
Example output (specificity):
| 0 | 2 | 2 |
See also: https://www.codecaptain.io/tools/css-specificity-calculator
will_paginate can paginate plain Ruby arrays
While you are probably using will_paginate to paginate ActiveRecord scopes, it can actually paginate plain Ruby arrays. The resulting arrayish object will have the same methods as a paginated scope, e.g. #total_entries. This means you can render pagination controls with the same code that works with paginated scopes.
To enable this, add an initializer config/initializers/array_paginate.rb:
require 'will_paginate/array'
You can now say:
> numbers = (1..1000).to_a
> page = numbers....
Font Awesome 3.0 has been released
40 new icons, spinner-style rotation with CSS animations, smaller file size, possibility to sub-set the font to only include the icons you need.
Get Your App Ready for Rails 4
Let’s take a look at what you need to do to get your app ready for Rails 4.
WORDOID - Creative Naming Service
A cozy place to pick a short and catchy name for your product, company or domain.
Rails 4 Countdown to 2013 | The Remarkable Labs Blog
With the impending release of Ruby on Rails 4, it looks like a lot of developers will be updating their web applications in the coming new year.
To help with this transition, over the next 31 days, we are going to be releasing a series of blog posts going over everything you will need to know about Rails 4 for an effortless upgrade.
Compare two jQuery objects for equality
Every time you call $(...) jQuery will create a new object. Because of this, comparing two jQuery collections with == will never return true, even when they are wrapping the same native DOM elements:
$('body') == $('body') // false
In order to test if two jQuery objects refer to the same native DOM elements, use is:
var $a = $('body');
var $b = $('body');
$a.is($b); // true
Jasmine equality matcher for jQuery
See [here](/makandra/34925-jasmine-testing-complex-types-for-e...
5 Design Tips Every Developer Should Know
If you wear a lot of hats in a small team, or if you feel like your projects could be more successful if they looked better, this is for you. Here are five traditional elements and principles of art and design that will cure the ugly (or at least disguise it).
The Shapes of CSS
Examples how to create dozens of shapes using pure CSS and a single HTML element.
King of Nothing, the DCI paradigm is a scam
I’ve worked on huge applications in Ruby and Rails before. I very much want to believe in DCI, but I’m having a hard time accepting the promises of Clean Ruby when it seems like the work on this paradigm is half-done. If it weren’t so oversold and hyped, I think I’d be more patient, but right now I’m just frustrated and confused.
Git blame: How to ignore white-space modifications
When doing a git blame, git will blame the person who added or removed white space in a line (e.g. by indenting), not the person who originally wrote the code.
Say git blame -w to ignore such white-space changes. You want this. \
Note that you can also use it when diffing: git diff -w.
Example
Consider this method, created by a user in commit d47bf443:
def hello
'world'
end
^
$ git blame foo
d47bf443 (Arne Hartherz 2012-12-19 14:44:38 +0100 1) def hello
d47bf443 (Arne Hartherz 2012-12-19 14:44:38 +0100 2...
Why your browser loses cookies when following hyperlinks from an Excel spreadsheet or Word document
Microsoft Office pre-fetches hyperlinks using an internal DLL (which doesn't know about your cookies), follows all redirects and opens your browser with the result. This is because of stupidity.
The "fix" is to not redirect but just render a text like "access denied" with 200 OK when you see that request.env['HTTP_USER_AGENT'].include?('ms-office').
randym/axlsx · GitHub
Axlsx is an incredible gem to generate "Office Open XML" spreadsheet files (XLSX). Does not break on large spreadsheets and supports a ton of features like graphs.
API looks mature and existing code is easy to migrate when coming from the spreadsheet gem.
The documentation of some methods is a bit out of date, but you'll find your way around the gem's code.
No support for reading files, however. :( If you want to open XLSX spreadsheets (for example to confirm your output in tests), you can use [roo](h...
Consul 0.4.2 improves querying of nil powers
Previous versions of Consul exhibited strange behavior when querying a power that returns nil.
Consul 0.4.2+ behaves as expected:
power.notes # => returns nil
power.notes? # => returns false
power.notes! # => raises Consul::Powerless
power.note?(Note.last) # => returns false
power.note!(Note.last) # => raises Consul::Powerless
occ/TraceKit · GitHub
Tracekit is a JavaScript library that automatically normalizes and exposes stack traces for unhandled exceptions across the 5 major browsers: IE, Firefox, Chrome, Safari, and Opera.