Count lines of code
The following counts all the lines in all *.rb files in the app directory. Run several of these commands to get a rough estimate of the LOC.
find app -name *.rb -exec wc {} \; | awk '{a+=$1;print a}' | tail -1
Find out which PID listens on socket
Show all sockets (Unix & TCP/UDP), both listening and established ones:
netstat -anp
To limit the output e.g. to listening TCP sockets:
netstat -anp | grep tcp | grep LISTEN
...
tcp 0 0 0.0.0.0:3000 0.0.0.0:* LISTEN 28683/server
...
This means: A tcp v4 socket listening on port 3000 on all IP adresses (0.0.0.0 is synonym to 'all interfaces on the machine').
The last column includes the PID, kill -9 28683 should exit the process and clean up the socket.
traits.js - Traits for Javascript
traits.js is a minimal, standards-compliant trait composition library for Javascript.
Announcing YARD 0.6.0 (gnuu.org)
YARD 0.6 adds the ability to serve documentation for gems as well as the current project with yard server. Just like gem server in RubyGems, you can serve gem docs. The advantage to YARD’s server is that you don’t need to pre-generate the static docs (with a gem install) before running the server. If you installed your gem with --no-rdoc, YARD will just generate it on the fly!
Change the color of a <hr> in all browsers
The following Sass will do it:
hr
color: #ddd
background-color: #ddd
border: none
height: 1px
Ruby Reports
Ruport’s acts_as_reportable module provides support for using ActiveRecord for data collection. You can use it to get a Ruport::Data::Table from an ActiveRecord model. This cheatsheet covers the basic functionality of acts_as_reportable and some common use cases.
Order for SELECT ... IN (5,100,23) queries
IN queries return rows in undefined order; ORDER BY FIELD() preserves a custom sequence for matching IDs.
Riding Rails: Rails 3.0: It's ready!
Rails 3.0 has been underway for a good two years, so it’s with immense pleasure that we can declare it’s finally here. We’ve brought the work of more than 1,600 contributors together to make everything better, faster, cleaner, and more beautiful.
Build a JSON API for a Rails application
Try our Apify gem which solves many problems you will be having.
MPEG LA’s AVC License Will Not Charge Royalties for Internet Video That Is Free to End Users Through Life of License | Business Wire
DENVER--(BUSINESS WIRE)--MPEG LA announced today that its AVC Patent Portfolio License will continue not to charge royalties for Internet Video that is free to end users (known as “Internet Broadcast AVC Video”) during the entire life of this License. MPEG LA previously announced it would not charge royalties for such video through December 31, 2015 (see http://www.mpegla.com/Lists/MPEG%20LA%20News%20List/Attachments/226/n-10-02-02.pdf), and today’s announcement makes clear that royalties will continue not to be charged for such video beyond...
mezzoblue's PaintbrushJS at master - GitHub
PaintbrushJS is a lightweight, browser-based image processing library that can apply various visual filters to images within a web page.
epeli / Underscore.strings / source — bitbucket.org
String helper extensions for Underscore.js add convenient text utilities to JavaScript projects.
Automagical ?-methods for boolean attributes in ActiveRecord
Boolean ActiveRecord attributes can get an automatically defined ? reader, letting User.email_confirmed? work without a custom method.
Only allow pictures as Paperclip attachments
Restricting uploads to image files prevents non-picture attachments from being accepted by Paperclip. A content-type validation blocks unsupported formats such as documents or audio.
Forward HTTP through an intermediary server (Local Port Forwarding)
Tunnel HTTP traffic to a specific host and port through an SSH server with local port forwarding, useful for reaching internal services from localhost.
Change default size of Gnome terminal
Open the configuration file:
gksudo gedit /usr/share/vte/termcap/xterm
Find a line like this:
:co#80:it#8:li#24:\
Change the first and last number to your desired columns and rows:
:co#160:it#8:li#40:\
Save your changes and close all open terminals. New terminals should now open with the new size.
Copy a file over SSH
Ubuntu lets you mount an SSH shell into Nautilus from Places -> Connect to server (select "SSH" as server type).
In order to copy a file over SSH from a shell:
scp filename username@remotehost:
The trailing ":" directs the file to username's home directory on the remote host.
You can also copy a file from the remote host to your local machine:
scp remotehost:remotepath localpath
Using screen for long running tasks
Screen is great for long running tasks, where you want to log in every few hours and days and keep your session alive indefinitely.
To create a new screen, do
screen -Rd screenname
This will also reattach an existing screen with that name.
Once you're in the screen, CTRL+A will bring up the menu, d detaches the screen. You can close your shell, screen and all applications running inside of it will remain alive.
Scrolling inside a screen
- Bring up the menu with
CTRL+A - Press
Esc - You can now scr...
Dumping and importing from/to MySQL in an UTF-8 safe way
MySQL dumps can corrupt UTF-8 when shell redirection changes character encoding. Using -r for export and SOURCE for import preserves the dump bytes.
UTF-8ify an existing MySQL database
MySQL databases can keep existing data in the wrong encoding unless tables are converted, not just reset to utf8 defaults. ALTER TABLE ... CONVERT TO CHARACTER SET updates stored text.
Count files in a folder
Count the number of files in a folder from the shell with ls -l | wc -l, a quick way to get a directory listing total.
jeremyevans's home_run at master - GitHub
home_run is an implementation of ruby’s Date/DateTime classes in C, with much better performance (20-200x) than the version in the standard library, while being almost completely compatible.
Using CSS3PIE cross-domain
Currently not possible as the linked .htc file contains JavaScript which is not explicitly called.
The developers are working on a pure JavaScript solution which will have some downsides but work across different domains.
Error installing the raspell gem
raspell installation can fail while building the native extension because the Aspell development libraries are missing. Installing libaspell-dev resolves the build error.