Why Most Freelancers Set Their Clients Up For Failure (And How To Fix This)
How you can unknowingly screw your client's business when all you think about is closing the next user story.
Rails routes: Extracting collection actions into their own controllers
Let's say you have two screens:
- Show a given project
- Show a report for all projects
Ideally you want both screens to be handled by different controllers like this:
GET /projects/:id => ProjectsController#show
GET /projects/report => Projects::ReportsController#show
What seems like a simple requirement is a little awkward to configure in your routes.
Obviously the report should be a singleton resource, but how can we nest it into the Projects:: namespace?
What does not work is this:
resources :proj...
Rspec: Complex argument expectations for should_receive
Sometimes you need complex expectations on method arguments like this
SomeApi.should_receive(:find).with(:query => '*foo*', :sort => 'timestamp ASC', :limit => 100).and_return(['some result'])
This is not very flexible, and failure messages will be hard to read.
Instead, consider doing this:
SomeApi.should_receive(:find) do |params|
params[:query].should == '*foo*'
params[:sort].should == 'timestamp ASC'
params[:limit].should == 100
['some result']
end
What we know about PDFKit
What PDFKit is
- PDFKit converts a web page to a PDF document. It uses a Webkit engine under the hood.
- For you as a web developer this means you can keep using the technology you are familar with and don't need to learn LaTeX. All you need is a pretty print-stylesheet.
How to use it from your Rails application
- You can have PDFKit render a website by simply calling
PDFKit.new('http://google.com').to_file('google.pdf'). You can then send the...
Complexity in Software 3: The Constructal Law
Talks about some basics of software complexity. Very nice illustrations.
JavaScript: Moving elements inside an array, modifying the array in place
If you want to move an element inside an array, neither JavaScript/ES6+ nor libraries like LoDash offet that natively.
Here is a simple function instead that modifies the input array in place.
function moveArrayElement(array, element, offset) {
const index = array.indexOf(element)
const newIndex = index + offset
if (newIndex > -1 && newIndex < array.length) {
// Remove the element from the array
const removedElement = array.splice(index, 1)[0]
// At "newIndex", remove 0 elements and insert the removed el...
Testing drag&drop with Selenium
When using jQueryUI's Sortable plugin (either directly or via Angular's ui.sortable), you might struggle testing your nice drag&drop GUI since Selenium webdriver does not support native dragging events.
But jQueryUI uses jquery.simulate for their testing, so why shouldn't you? There is even an extension to it that makes testing drag & drop quite easy.
Here is what you need:
jquery.simulate.js- [`jquery.simula...
Transactional HTML Email Templates
Styling HTML email is painful. Tables, inline CSS, unsupported CSS, desktop clients, web clients, mobile clients, various devices, various providers. All these things have to be thought about and tested. It’s no surprise developers don’t want to deal with this when there is a backlog of more important priorities.
We’ve tried to remove some of the pain for you and open-sourced a collection of common templates for transactional email.
Alternative transactional email templates include
- [these ones...](https://www.sendwithus.com/resource...
Rails 3: Mass assignment protection and .create_with
The issue
Yesterday, Rails fixed a security issue (CVE-2014-3514) in Rails 4+. It was possible to use .where or .create_with to bypass Rails' Strong Parameters:
user.blog_posts.create_with(params[:blog_post]).create
would set all attributes on the blog post. After the fix, you have to properly whitelist the params, via `params[:blog_post].permit(:title, :bo...
jQuery: Work with text nodes and comment nodes
Nearly all jQuery traversal functions ignore elements that are not HTML tags.
To work with other type of nodes (like text, comment or CDATA sections) you need to:
- Retrieve child nodes
contents()(which behaves likechildren()except that it returns all types of child nodes) - Filter manually using either plain Javascript or jQuery's
filter()method
Example
Let's write a function that takes a jQuery element and returns an array of all child nodes that are text nodes:
function selectTextNodes($container) {
retu...
Vastly increase the usability of Thunderbird's search
These two addons will change your life:
- Search as list
-
This will always open search results in the list views instead of the barely usabely faceted search view.
- Sort search results by date not relevance
-
Does what it says.

Interacting with a Microsoft Exchange server from Ruby
Microsoft Exchange service administrators can enable Exchange Web Services (EWS) which is a rather accessible XML API for interacting with Exchange. This allows you to read and send e-mails, create appointments, invite meeting attendees, track responses, manage to-do tasks, check user availability and all other sorts of things that are usually only accessible from Outlook.
You can implement an EWS by hand-rolling your XML (the [docs](http://msdn.microsoft.com/en-us/...
Rest-ORM for Angular: Restmod
Restmod creates objects that you can use from within Angular to interact with your RESTful API.
Alternative for Ruby singletons
require 'net/http'
module Cheat
extend self # the magic ingredient
def host
@host ||= 'http://cheat.errtheblog.com/'
end
def http
@http ||= Net::HTTP.start(URI.parse(host).host)
end
def sheet(name)
http.get("/s/#{name}").body
end
end
# use it
Cheat.sheet 'migrations'
Cheat.sheet 'singletons'
Full list of Skype emoticons and icons
Unfortunately, the hidden emoticons are some of the most expressive and useful ones.
Hidden codes
(skype) (ss)
(call)
(talk)
(u) (U)
(o) (O) (time)
(e) (m)
(~) (film) (movie)
(mp) (ph)
(drunk)
(punch)
(smoking) (smoke) (ci)
(toivo)
(rock)
(headbang) (banghead)
(bug)
(poolparty)
(talktothehand)
(idea)
(sheep)
(cat) :3
(bike)
(dog)
The U.S. Digital Services Playbook
The The U.S. Digital Services Playbook is pretty amazing (context).
DevDocs - Documentation Browser
DevDocs combines multiple API documentations in a fast, organized, and searchable interface.
Pretty awesome project. You can select multiple docs to be searched simultaneously, offline in your browser. Supports OpenSearch, so you can hit Tab in your Chrome and search your downloaded docs.
Mac OS Fix: Opening new Terminal tabs/windows takes ages
See the solution on Ask Different (same answer found here).
Hexbook | A Public Library of Beautiful Hexcodes
Inspiring collection of color tones.
Angular directives: How to find out if you have transcluding content
When you have an Angular directive that transcludes content, you might want to do something in case there is no content inside your element, like showing some default content.
Unfortunately, you can not do something like <span ng-transclude>default goes here</span>. Angular will always empty that element's text, even if there is nothing to transclude.
But you can use your directive's link function. Here's some CoffeeScript for you:
@app.directive 'myStuff', [->
restrict: 'E'
transclude: true
te...
MySql lost connection trouble
Directly from the MySql docs:
There are three likely causes for this error message.
Usually it indicates network connectivity trouble and you should check the condition of your network if this error occurs frequently. If the error message includes during query, this is probably the case you are experiencing.
Sometimes the during query form happens when millions of rows are being sent as part of one or more queries. If you know that this is happening, you should try increasing net_read_timeout from its default of 30 seconds to 60 s...
Feedjira
Great gem to consume RSS feeds. I was missing some features on Ruby's RSS::Parser that I found in Feedjira:
- Speed
- Does not break on slightly malformed RSS feeds (like a missing
lengthattribute on an<enclosure>tag on gizmodo.de's feed) - It automatically resolves Feedburner-mangled URLs (hooray!)
The GitHub project has only a minimalistic readme. You can find its documentation on their homepage.