Posted by Kenneth Kalmer
on May 01, 2009
Just thought I’d share this one to boost the available online information. Using String#crypt and man crypt you’ll come up with something similar to the gist below (extract from a project I’m busy working on).
module Linux
class User
class << self
# Generate an MD5 salt string
def salt
seeds = ('a'..'z').to_a
seeds.concat( ('A'..'Z').to_a )
seeds.concat( (0..9).to_a )
seeds.concat ['/', '.']
seeds.compact!
salt_string = '$1$'
8.times { salt_string << seeds[ rand(seeds.size) ].to_s }
salt_string
end
# Crypt a password suitable for use in shadow files
def crypt( string )
string.crypt( self.salt )
end
end
end
end
And the spec
require File.dirname(__FILE__) + '/../spec_helper'
describe Linux::User do
describe "generating shadow passwords" do
it "should generate a salt for crypt" do
salt = Linux::User.salt
salt.length.should be(11)
salt.should match(/^\$1\$[a-zA-Z0-9\.\/]{8}$/)
end
it "should generate a shadow password" do
pass = Linux::User.crypt( 'secret' )
pass.should match(/^\$1\$[a-zA-Z0-9\.\/]{8}\$[a-zA-Z0-9\.\/]{22}$/)
pass.length.should be(34)
end
end
end
HTH
Posted by Kenneth Kalmer
on March 20, 2009
I was busy merging work back and forth between topic branches today and by accident miss-merged a 700-line spec. Everything else was fine (or so I hope) except this one file. I couldn’t use git revert, since that would mean I’ll have to redo all the merges I made.
So in panic I googled and read several man pages, coming to the following conclusion that worked quite well:
- Find the offending commit with git log or git log -p, not the revision number prior to the catastrophic change.
- View the file at that point in time with git show SHA-ID:path/to/file
- Replace current copy with git show SHA-ID:path/to/file > path/to/file
- Verify the damage has been undone with git diff
- Commit
- Breathe
Git is a double edged sword, it is extremely powerful and useful, but can be a real pain in the behind. I love git, and will not easily be convinced to move to something else.
Posted by Kenneth Kalmer
on November 21, 2008
I hit a barrier last night where my virtual machine I use for Rails development ran out of space. I quickly checked around and saw my current Rails project had 800MB in log files (thanks autospec).
So I decided to quickly cook up this little bash script that I run from my top level working directory, and have it clear all the log files, in all my Rails projects.
Hope it helps.
Posted by Kenneth Kalmer
on October 23, 2008
Just a quickie to tell you about my (first) latest gist: http://gist.github.com/19021
Basically search through the postfix maillog for a pattern, extract the postfix message id from each matched line, and then search through the log file for each corresponding line.
This rebuilds your original search with some more context, and makes it a snap to trace a message through its lifecycle…