Parse & sort unique hits in logfiles
If you want to know the exact hits on your website (or whatever logfile you want) for a specific date without duplicates, here's how.
"Unique" means you don't want to count hits to an URL originating from the same IP twice.
You can use the attached script to do so:
# ./log_parser.rb 2011-10-04
27 hits on /rss.xml
36 hits on /stylesheets/fonts/slkscr-webfont.woff
37 hits on /stylesheets/fonts/slkscrb-webfont.woff
37 hits on /images/bullet.png
38 hits on /images/download.png
38 hits on /images/play.png
39...
How to use CSS3 gradients in Opera
Since version 11.10 Opera provides support for linear gradients using -o-linear-gradient
.
The syntax is pretty similar to Mozilla's -moz-linear-gradient
. This will create a vertical gradient from yellow to red:
background-image: -o-linear-gradient(top, #ff0, #f00);
The first parameter defines where the gradient starts and which direction it will go. \
You can use top
/left
/bottom
/right
(and combinations of those) but also set any angle you like (0° being the left side, going counter-clock-wise):
background-image: -o-l...
Removing ANSI color codes from Rails logs
The colors in Rails log files are helpful when watching them but, since they are ANSI color codes like ^[[4;36;1m
, can be annoying when you are reading the logs with a tool that does just prints those control characters (like less
or vim
).
Remove them with sed
:
cat staging.log | sed -r "s/\x1B\[([0-9]{1,3}((;[0-9]{1,3})*)?)?[m|K]//g"
This will print the log without colors to your terminal. You can pipe the result into less
for example.
To have a file you can vim
around with, just write that output into a new file:
ca...
Auto-generate state_machine graphs as PNG images
The state_machine gem comes with a rake task that lets you generate PNG graphs from any model using state_machine
.
Install the required dependencies like this:
sudo apt-get install graphviz
sudo gem install ruby-graphviz
You can now generate a graph like this:
rake state_machine:draw CLASS=ModelUsingStateMachine
Replace ModelUsingStateMachine
with the name of your model class.
If it the raketask does not exist for you, add to Rakefile
(in your pr...
Backup your Mac to an encrypted local hard drive
There are many blog posts on encrypting backups, but none works for local drives.
#How to
- Encrypt the external backup drive using TrueCrypt or PGP or similar.
- Mount it. If possible, let this happen automatically.
- Tell Time Machine to use it for backup.
#What is NOT working
- Backing up to disk images as described in this blog post. Apparently,
sparsebundle
images & co. ar...
xdissent/ievms - GitHub
Microsoft provides virtual machine disk images to facilitate website testing in multiple versions of IE, regardless of the host operating system. Unfortunately, setting these virtual machines up without Microsoft's VirtualPC can be extremely difficult. These scripts aim to facilitate that process using VirtualBox on Linux or OS X. With a single command, you can have IE6, IE7, IE8 and IE9 running in separate virtual machines.
When Balsamiq Mockups won't let you load an image file
Did you check Copy to Projects Asset as ... and there is an existing file with the same name in your project folder?
Convert the colorspace of a PDF from RGB to CMYK under Ubuntu Linux
Note that converting from RGB to CMYK will usually degrade your colors because no exact mapping is possible. Anyway, this Stackoverflow post worked for me:
gs -dSAFER -dBATCH -dNOPAUSE -dNOCACHE -sDEVICE=pdfwrite \
-sColorConversionStrategy=CMYK -dProcessColorModel=/DeviceCMYK \
-sOutputFile=output.pdf input.pdf
How to make a single check box (or image, etc) align vertically
Consider this HTML:
<div style="line-height: 42px">
<input type="checkbox" />
</div>
Even though the surrounding container defines a line-height
, which vertically centers its inline elements, the check box will be top aligned if it is the only element inside the container.
It will be aligned correctly if the HTML looks like this:
<div style="line-height: 42px">
<input type="checkbox" /> foo
</div>
So the ac...
Solarized color scheme for Rubymine
If you want to use the (badly implemented!) solarized color scheme in your Rubymine IDE:
-
Clone the IntelliJ IDEA port:
git clone https://github.com/jkaving/intellij-colors-solarized.git
-
Import the settings in Rubymine by chosing the above directory
File -> Import Settings
-
Change the color scheme in the settings (Ctrl-Alt-S) in
Editor -> Colors & Fonts
Note that selecting a color scheme will also reset your previous editor font choice. You might want to change the font to [Envy Code R](http://damieng.com/blog/2008/05/2...
Solarized
Solarized is a sixteen color palette (eight monotones, eight accent colors) designed for use with terminal and gui applications. It has several unique properties. I designed this colorscheme with both precise CIELAB lightness relationships and a refined set of hues based on fixed color wheel relationships. It has been tested extensively in real world use on color calibrated displays (as well as uncalibrated/intentionally miscalibrated displays) and in a variety of lighting conditions.
Always store your Paperclip attachments in a separate folder per environment
tl;dr: Always have your attachment path start with :rails_root/storage/#{Rails.env}#{ENV['RAILS_TEST_NUMBER']}/
.
The directory where you save your Paperclip attachments should not look like this:
storage/photos/1/...
storage/photos/2/...
storage/photos/3/...
storage/attachments/1/...
storage/attachments/2/...
The problem with this is that multiple environments (at least development
and test
) will share the same directory structure. This will cause you pain eventually. Files will get overwritten and...
Check whether a Paperclip attachment exists
Don't simply test for the presence of the magic Paperclip attribute, it will return a paperclip Attachment
object and thus always be true:
- if user.photo.present? # always true
= image_tag(user.photo.url)
Use #exists?
instead:
- if user.photo.exists?
= image_tag(user.photo.url)
How to grep through the DOM using the Capybara API
When your Cucumber feature needs to browse the page HTML, and you are not sure how to express your query as a clever CSS or XPath expression, there is another way: You can use all
and find
to grep through the DOM and then perform your search in plain Ruby.
Here is an example for this technique:
Then /^I should see an image with the file...
How to diff two strings in Ruby
When you need to use diff
in either some Ruby code or your Rails app, use the differ gem.
puts Differ.diff "foo", "boo"
# => {"boo" >> "foo"}
Usage
There are several variants available, all using the base method diff(to, from, separator = "\n")
.
You have diff_by_line
, diff_by_word
, diff_by_char
and may of course use your own separator:
puts Differ.diff 'Hauptsatz, und mein Nebensatz.', 'Hauptsatz, und dein Nebensatz.', ','
# => Hauptsatz,{" und dein Nebensatz." >> " un...
How to look at hidden X screens
When you have a program running in a hidden X screen (like with Xvfb for Selenium tests) you may want to look at that hidden screen occasionally.
First, find out what X displays are currently active:
netstat -nlp | grep X11
This should give you some results like these:
unix 2 [ ACC ] STREAM LISTENING 8029600 4086/Xvfb /tmp/.X11-unix/X99
unix 2 [ ACC ] STREAM LISTENING 8616 - ...
Hex color codes for the CGA palette
Below you can find the hex color codes for the Color Graphics Adapter palette which used to be popular in the 1980s.
$cga_black: #000000
$cga_white: #ffffff
$cga_light_gray: #aaaaaa
$cga_dark_gray: #555555
$cga_yellow: #ffff55
$cga_brown: #aa5500
$cga_light_red: #ff5555
$cga_dark_red: #aa0000
$cga_light_green: #55ff55
$cga_dark_green: #00aa00
$cga_light_cyan: #55ffff
$cga_dark_cyan: #00aaaa
$cga_light_blue: #5555ff
$cga_dark_blue: ...
How to enlarge a VirtualBox VDI disk file
VirtualBox does not offer anything for this task -- you need to do it yourself. It's not that hard:
Get more disk space
- Add an extra virtual hard disk to the machine with the disk size you want to achieve.
- Get a Linux live CD (like the Ubuntu live image) that offers
fdisk
,dd
andgParted
. - Boot the guest from the CD, open a terminal (on the guest, not the host!) and become root:
sudo su
-
fdisk -l
to see the disk information. \
There should be one drive with some partitions and one without any....
Disable Thumbs.db on Windows 7
Every time you open a directory containing images, Windows creates those pesky Thumbs.db
files for a minor speed-up and lots of cluttering your zip files etc.
You do want to disable them. Here is how on Windows 7:
- Start → Run (or press Meta+R)
- gpedit.msc
- User Configuration → Administrative Templates → Windows Components → Windows Explorer
- Locate "Turn off the caching of thumbnails in hidden thumbs.db files" (should be one of the top list entries)
- Set it to "Enabled". Yes, seriously -- you enable the disabling of thumbs.d...
Getting non-Aero toolbars for Thunderbird 5 on Windows 7
Thunderbird 5 brings a custom chrome on Windows Vista/7 that uses translucent Aero decorations on toolbars and menubars. Here is how to restore solid backgrounds if you don't like it.
Put the following into chrome\userChrome.css
in your Thunderbird profile directory:
@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
window {
background-color: -moz-dialog !important;
}
(Re-)start Thunderbird afterwards.
If you need more info on where the userChrome.css
is suppose...
How to fix zero-byte downloads with Rails 3 and Apache / Passenger
You probably need to activate X-Sendfile.
Manipulate color with Sass functions
Sass comes with many built-in functions to manipulate color. Some of the more interesting functions include:
adjust-hue($color, $degrees)
:Changes the hue of a color.
lighten($color, $amount)
:Makes a color lighter.
darken($color, $amount)
:Makes a color darker.
saturate($color, $amount)
:Makes a color more saturated.
desaturate($color, $amount)
:Makes a color less saturated.
grayscale($color)
:Converts a color to grayscale.
complement($color)
:Return...
A nicer way to run RSpec and/or Cucumber
geordi, our collection of awesome shell scripts, has been extended by three scripts to help you call RSpec or Cucumber:
cuc
This script runs Cucumber the way you want it:
- Prints some line feeds to easily find your test results when you come back to the console later
- Configures Cucumber to use cucumber_spinner if it is available in your
Gemfile
- Runs Cucumber under
bundle exec
- Uses an old version of Firefox for Selenium (Javascript) features...
Setting up FreeBSD as Virtual Machine in VMware
Install FreeBSD
- Download a suitable image from this site
- Select
File > New…
to and follow the instructions, choose the.iso
file you downloaded as image file - Start the new virtual machine and follow the instructions
- formatting is a little complicated, so let freebsd.org help you
Install VMware Tools
Choose Virtual Machine > Install VMware Tools
from the VMware menu, then as root
:
^
# install required packages
pkg_add...