Posted by neomorphic
Sun, 06 Jul 2008 22:00:00 GMT
So I thought I would try out git and github and see what all the cool kids are talking about. The initial setup was really easy. I got my first repository setup within minutes and was committing without any problems. Then I created a clone on my laptop and continued working. The problem arose when I tried to get this work back into the central repository and then back to my desktop. The git push was fine, but the git pull kept failing giving me the following:
neo$ git pull
You asked me to pull without telling me which branch you want to merge with,
and 'branch.master.merge' in your configuration file does not tell me either.
Please name which branch you want to merge on the command line and try again
(e.g. 'git pull <repository> <refspec>'). See git-pull(1) for details on the refspec.
If you often merge with the same branch, you may want to configure the following
variables in your configuration file:
branch.master.remote = <nickname>
branch.master.merge = <remote-ref>
remote.<nickname>.url = <url>
remote.<nickname>.fetch = <refspec>
Having a quick search around the net, told me that I needed to update only the branch.master.remote and the branch.master.merge. Since I am merging with the 'origin' branch, I run:
neo$ git config branch.master.remote origin
Then to get the merge to work correctly I set the following:
neo$ git config branch.master.merge refs/heads/master
This tells git to merge the remote changes into the master branch. Once done a simple
neo$ git pull
should do the trick.
Posted in Programming | Tags git | no comments
Posted by neomorphic
Mon, 23 Jun 2008 22:24:00 GMT
Jeff Atwood of
Coding Horror fame has written a
neat overview of ways to become a better programer. I like the advice that he provides, especially that "programming every day may not be enough to make you a professional programmer." Have a read and see what you think. Maybe you would like to join me for a few technical interviews.
Posted in Programming, Education | no comments
Posted by neomorphic
Sun, 08 Jun 2008 17:20:00 GMT
I think this is a brilliant ad. Not sure I want to buy bottled water, but this made me think about it :-)
http://www.youtube.com/v/7-ZAmVF6crE&hl=en
Posted in General | Tags advertising, fun, thunderbirds, water | no comments
Posted by neomorphic
Sat, 09 Feb 2008 19:58:00 GMT
So, I was trying to uppercase the first letter of all the words in a string. For example:
'the example string' -> 'The Example String'
So I had a look around and found this great little snippet of code:
'the example string'.gsub(/\b\w/){$&.upcase}
Check out the original post here:
http://snippets.dzone.com/posts/show/4702
Laters,
J.
Posted in Programming | Tags capitalize, code, ruby, snippet | no comments
Posted by neomorphic
Sun, 13 Jan 2008 19:34:00 GMT
So, I thought it would be a good idea to get used to the ruby build tool Rake. It merges some of the best features of ant and make in a nice neat ruby bundle, to create a really useful build tool with direct access to a powerful scripting language. After much playing around and reading excelent articles on the subject:
- Rails envy tell you all you need to get started using some very funny analogies.
- Martin Fowler takes a more in depth look at how rake stacks up against other build languages like make and ant.
After reading for a while, I thought it would be a good idea to create a simple Rakefile and make sure that I understood what I had read. For my first attempt I created the 'hello world' of Rakefiles:
require 'rake'
task :default => :hello
desc 'Say hello'
task :hello do
puts 'Hello World'
end
Once saved I was ready to give my new code a test drive. I fired up the command line and:
anon@box:~/ruby$ rake
(in /home/anon/ruby)
Hello World
I was in inspired by the ease with which I had written a simple rake task. So I decided to create a slightly more complex one using namespaces. Namespaces allow you to group related tasks with a common prefix, making it easier to figure out which tasks to call when you return to the script at a later date. It also allows you to have tasks with the same name perform different actions. A common example would be cleaning up files, directories and databases. It makes sense to name these actions clean or cleanup as that is the function they are performing. However, you can imagine the chaos if there were three tasks in a single Rakefile all with the same name. To get around this we use namespaces:
namespace :database do
task :clean do
#clean up the database
end
end
namespace :files do
task :clean do
#clean up the files
end
end
namespace :dir do
task :clean do
#clean up the directory structure
end
end
Now all three tasks can be called from the same Rakefile and all that needs to be done is to prefix them with the namspace. To clean the database you would run rake like this:
rake database:clean
This was all working great, until I tried to make one of the tasks created in a name space the default task.
require 'rake'
task :default => :logs:clean
namespace :logs do
desc 'Clean up generated files'
task :clean do
#delete generated files
end
end
It turns out that ruby symbols don't like to have a ':' in them. After some digging
Posted in Programming | Tags
rake,
ruby | no comments
Posted by neomorphic
Sat, 29 Dec 2007 13:44:00 GMT
I have been getting a huge number of failed login attempts on my web server. These have been anoying for two reasons.
- Someone is trying to hack into my machines.
- The machine can slow to a crawl when trying to deal with the thousands of requests that I am getting. Causing my web services to slow down.
So, the question is:
How can I deal with this?
Some common suggestions:
- Change your port to a non-standard port such as 2222, or some other random number. I agree that this does work, but it can be annoying if my applications cant be configured to connect to a non-standard port.
- Use port knocking to keep the port closed, until the right sequence of ports have been probed. This sounds more elegant than changing the port number, but again if my programs cant do this, then I need some sort of hack to get the port open.
I have gone for a slightly different approach, which is to setup a cronjob to monitor my log files and add the offenders to a list of banned ip addresses. The code was written in ruby and is running on a debian server
Without further ado, here is the code:
#!/usr/bin/ruby -T
# hash of found ips used to store the ips found in the
# auth.log
ipFound = Hash.new(0)
puts 'Checking for scanning attempts'
# 1. read in the auth.log
authLog = File.open('/var/log/auth.log','r')
authLog.each_line { |line|
# 2. check for the ip addresses that are scanning
if line =~ /Failed password for invalid user/
if line =~ /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/
@ipaddress = $1
#add it to the list
ipFound[@ipaddress] += 1
end
end
}
authLog.close
# hash used to store the ips that are already banned
ipDenied = Hash.new(0)
# open the list of banned ip adresses
hostsDeny = File.open('/etc/hosts.deny','r')
hostsDeny.each_line { |line|
if line =~ /ALL:(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/
ipDenied[$1] += 1
end
}
hostsDeny.close
# if ip not in denied list or from the local network,
# then add it
hostsDenied = File.open('/etc/hosts.deny','a')
ipFound.each_pair { |ip,count|
puts "IP:#{ip} -> #{count}"
if ipDenied[ip] != 0
puts "IP Already denied"
next
end
if ip =~ /^192.168.1/
puts "IP in local network"
next
end
if count < 10
puts "Didn't scan that much"
next
end
puts "Adding to the denied list"
hostsDenied << "ALL:#{ip}\n"
}
hostsDenied.close
puts "Done"
And that's all there is for the code. Then all I did was install it in the root crontab with the following line:
10 * * * * /path/to/banning_code 2>&1 | Mail -s 'offender ban run' you@your.domain
Now it gets run every ten minutes and adds login offenders to the banned list. There is loads more that could be done with this code and it doesn't check for some edge cases, but it will catch most of the script kiddies and get rid of them, until their ip address changes :-(
Posted in Programming | Tags cron, portscan, ruby, ssh | no comments
Posted by neomorphic
Sat, 15 Dec 2007 10:27:00 GMT
Have you ever come across this error:
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = "en_GB:en",
LC_ALL = (unset),
LANG = "en_GB.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
It turns out that this can be easily solved in a couple of steps (on debian).
- install the locales package:
apt-get install locales
- reconfigure your locale:
dpkg-reconfigure locales
No more nasty perl warnings.
Posted in Programming | Tags configuration, debian, howto, locale | no comments
Posted by neomorphic
Sat, 15 Dec 2007 00:42:00 GMT
So, today I thought I would try installing Typo, the ruby blog software. The initial install attempts lead to a few problems.
- After creating a fresh debian install and using apt to get ruby and gems tried to run 'gem install typo'. Everything seemed to go well, until I actually tried to run the typo install command. It wasn't there. Apparently the debian version of gems is broken and wont install the required stubs into the /usr/bin directory. To get around this I had to manually install the gems package from rubygems.org.
- With gems manually installed I tried to get typo yet again. This time I received an error message stating that SSL was not installed on the system. Fixing this required an apt-get of openssl and libopenssl-ruby
- After finally getting rails and typo installed I tried running the typo command yet again. The failure this time complained about the migrate task not working. This turned out to be due to the rails version being too new. So, I downgraded the installed version of rails to 1.2.6 from 2.0.1 and everything worked fine.
Posted in Programming | Tags blog, gem, installation, ruby, software, typo | no comments