cat log_file.txt | ruby -ne 'split(":").each { |col| print col , "\n" if col.match(/^\S+@\S+$/) }' | sort | uniq
Monday, April 27, 2009
ruby script to search for email addresses in a log file
Given input that is ":" delimited, this script will search out email addresses in any field in the input:
Wednesday, April 22, 2009
awk script to add up lines in a file
You want to add up the numbers in a file?
Input:
Script:
Input:
56168
796
44
26
202
258
478
632
Script:
cat file | awk '{ total = total + $1} END { print total}'
Tuesday, September 23, 2008
Getting jruby running with mysql on ubuntu
You want to get jruby running quickly on ubuntu using mysql as a backing store?
Unfortunately, it does not "just work" with sqlite3 out of the box on ubuntu for some reason. I don't really care why, as mysql is very easy to setup. The most important step that flexed my googling muscles was setting the database adapter to jdbcmysql in the database.yml file.
I will post later on a howto to get this working with glassfish and war files. For some reason, warbler nor goldspike "just work" on ubuntu either.
Unfortunately, it does not "just work" with sqlite3 out of the box on ubuntu for some reason. I don't really care why, as mysql is very easy to setup. The most important step that flexed my googling muscles was setting the database adapter to jdbcmysql in the database.yml file.
I will post later on a howto to get this working with glassfish and war files. For some reason, warbler nor goldspike "just work" on ubuntu either.
# install mysql
sudo apt-get install mysql-server mysql-client libhtml-template-perl mailx dbishell libcompress-zlib-perl mysql-doc-5.0 tinyca
# install ant and jdk
sudo apt-get install ant sun-java6-jdk
# install jruby
cd software
wget http://dist.codehaus.org/jruby/jruby-bin-1.1.4.tar.gz
tar xvfz jruby-bin-1.1.4.tar.gz
ln -s jruby-1.1.4 jruby
export PATH=$PATH:$HOME/software/jruby/bin
# install the version of rails wanted by jruby
jruby -S gem install jruby-openssl
jruby -S gem install rails
# list your gems
jruby -S gem list
# install the gems needed for db
jruby -S gem install activerecord-jdbc-adapter activerecord-jdbcmysql-adapter
# generate some code
cd ~/scripts/ruby
jruby -S rails wherehaveyoubeen -d mysql
cd wherehaveyoubeen
jruby script/generate controller states index
# configure access to the database server
vi config/database.yml
#development:
# adapter: jdbcmysql <- very important!
# encoding: utf8
# database: wherehaveyoubeen_development
# username: root
# password: database
# socket: /var/run/mysqld/mysqld.sock
# generate the db
jruby -S rake db:create:all
jruby -S rake db:migrate
# edit your app
sudo apt-get install emacs ruby-elisp irb1.8 emacs22-el
emacs -bg black -fg wheat app/views/states/index.html.erb
# uncomment the secret in app/controllers/application.rb
vi app/controllers/application.rb
# run your app
jruby script/server
# go to your app
GET http://0.0.0.0:3000/states
Monday, September 22, 2008
Adding subversion to eclipse on linux (ubuntu)
You want to use subversion in eclipse? You will need a javahl implementation.
Ubuntu has a javahl package:
Then add this to your eclipse.ini:
Ubuntu has a javahl package:
sudo apt-get install libsvn-java
Then add this to your eclipse.ini:
-Djava.library.path=/usr/lib/jni
Monday, August 4, 2008
Simple shell for loop
Simple for loop in shell to run a command n times.
for i in `seq 1 10`; do your_command_here.sh; done;
Sunday, July 27, 2008
Find a class in a lot of JAR files
Where did that class come from? Which JAR do I need to import to resolve this compilation error? Arrgh.
find ./ -type f -name "*.jar" -print -exec jar tvf {} \; | less
Thursday, July 10, 2008
Example Java code for posting to blogger.com using labels/tags
So I really can't believe how long it took to get this right, but here is some example code for posting to blogger.com with the ability to add some tags or categories or labels.
You just try searching for some code example on how to "post to a blog using tags". Jeez, it took about 45 minutes of searching to find an actual post that WASN'T a blog post that had a tag.
You just try searching for some code example on how to "post to a blog using tags". Jeez, it took about 45 minutes of searching to find an actual post that WASN'T a blog post that had a tag.
public class GoogleBlogPostTest extends TestCase { public void testBlogPost() throws Exception { GoogleService myService = new GoogleService("blogger", "company-xampleApp-1"); myService.setUserCredentials("googleusername", "googlepassword"); String title = "This is my title " + (new Date()).toString(); String blogID = "blognumber"; String contentStr = "This is a test of the emergency blogging system"; String authorName = "Test Author"; String userName = "author@email.com"; String summary = "This is the summary"; ArrayListtags = new ArrayList (); tags.add("News"); tags.add("Alerts"); Entry myEntry = new Entry(); for(String tag : tags) { Category category = new Category(); category.setScheme("http://www.blogger.com/atom/ns#"); category.setTerm(tag); myEntry.getCategories().add(category); } Content content = new TextContent(new PlainTextConstruct(contentStr)); myEntry.setTitle(new PlainTextConstruct(title)); myEntry.setContent(content); Person author = new Person(authorName, "http://flatebo.org", userName); myEntry.getAuthors().add(author); myEntry.setSummary(new PlainTextConstruct(summary)); URL postUrl = new URL("http://www.blogger.com/feeds/" + blogID + "/posts/default"); Entry newEntry = myService.insert(postUrl, myEntry); assertEquals(title, newEntry.getTitle().getPlainText()); } }
Labels:
blogger,
blogger.com,
categories,
frustrating,
gdata,
google,
google API,
java,
labels,
tags
Tuesday, June 3, 2008
Using microsoft VPN on ubuntu hardy in KDE
In the newest ubuntu, there is a package for kde to use network-manager in the tray to connect to microsoft VPN (PPTP).
Then just use the network manager app in the tray to define your VPN connections. When you are ready to connect, just right click and connect.
sudo apt-get install network-manager-pptp network-manager-vpnc \
network-manager-openvpn network-manager-kde
Then just use the network manager app in the tray to define your VPN connections. When you are ready to connect, just right click and connect.
How to reset IIS
c:\> iisreset
This also resets the exchange services on a Small Business Server install.
Monday, June 2, 2008
How to unzip 'encrypted' zip files in linux
sudo apt-get install p7zip-full p7zip p7zip-rar
bash$ 7z e filename.zip
(it will prompt you for the password)
Subscribe to:
Posts (Atom)