Displaying articles with tag _why
Posted by hank,
Sun Mar 30 21:16:00 UTC 2008
Today, I decided I wanted a network service that propagated variables and aliases to every login shell that subscribed to it. This is dangerous on a large scale, but perfectly acceptable on my small home network where everyone trusts everyone else.
First, I got Camping installed, bringing back fond memories of Ruby development. I then copied off the blog example, and created TreeHugger, a 427 line script that provides a web interface to edit the variables, and a plain text output for the shells to source.
This script, when run, allows some simple MVC actions to an sqlite3 database.

As you can see, I have some aliases here I want to send to all the subscribing hosts. Eventually, I want to add some detection functionality to the database (mostly reverse DNS lookups for host rule referencing). I just have to access /out to get my desired output:
# Treehugger Configuration
# Aliases
alias ai='sudo apt-get install'
alias aup='sudo apt-get update'
alias aug='sudo apt-get upgrade'
# Environment Variables
Now, to get this into bash. I looked into making the date command spit out pretty unique timestamps. Turns out you can do this with the nanoseconds format:
$ date +%s%N
1206926780157462141
I made it so wget saves the treehugger config to a tempfile using the somewhat random seed above as a filename suffix, and then I have my shell source it:
FILENAME=/tmp/treehugger-`date +%s%N`; 2>/dev/null wget -O $FILENAME http://rofl.who/treehugger/out && source $FILENAME && rm $FILENAME
And now I have nice aliases on my laptop served up from my desktop as fresh as the shell:
hank@davros:~$ alias
alias ai='sudo apt-get install'
alias aug='sudo apt-get upgrade'
alias aup='sudo apt-get update'
alias ls='ls --color=auto'
Tags: _why
Posted by hank,
Sun Aug 19 13:42:00 UTC 2007
Of course I know that a simple Greasemonkey script can very easily thwart this, but I don’t expect most people to go out and find it to defeat this. If you don’t like my google ads, you can read this wonderful entry.
function sendJerksAway() {
// Bye
eval(unescape("%69%66%28%24" +
"%24%28%75%6e%65%73%63%61%70%65" +
"%28%27%25%35%62%25%36" +
"%65%25%36%31%25%36" +
"%64%25%36%35%25%33" +
"%64%25%36%37%25%36%66%25%36%66%25" +
"%36%37%25%36%63%25%36%35%25" +
"%35%66%25%36%31%25%36%34%25%37%33%25%35%66" +
"%25%36%36%25%37%32%25" +
"%36%31%25%36%64%25%36%35%25%35%64%27%29%29%2e%6c" +
"%65%6e%67%74%68%20%3d%3d" +
"%20%30%29%20%64%6f%63%75%6d%65%6e%74" +
"%2e%6c%6f%63%61%74%69%6f" +
"%6e%20%3d%20%22%68%74%74%70%3a" +
"%2f%2f%67%6f%6f%67%6c%65%2e%62%6c%6f" +
"%67%6e%65%77%73%63%68" +
"%61%6e%6e%65%6c%2e%63%6f%6d" +
"%2f%61%72%63%68%69%76%65%73" +
"%2f%32%30%30%37%2f%30%37" +
"%2f%32%34%2f%67%6f%6f%67%6c%65%2d%72%65%63%6f%6d" +
"%6d%65%6e%64" +
"%73%2d%74%75%72%6e%69%6e%67" +
"%2d%6f%66%66%2d%61" +
"%64%62%6c%6f%63%6b%2f%22"));
}
Then it’s just this:
<body onLoad="sendJerksAway();">
Tags: _why
Posted by hank,
Fri Jul 20 00:41:00 UTC 2007
I’m not one to advocate Java generally, but Processing is totally hawt. Here’s something I screwed around with today:
Ball[] myBalls;
void setup()
{
size(500,500);
frameRate(25);
myBalls = new Ball[300];
for (int i = 0; i < 300; i++) {
myBalls[i] = new Ball();
myBalls[i].x = random(0, 500);
myBalls[i].y = random(0, 500);
myBalls[i].r = random(0, 10);
myBalls[i].xv = random(-5, 5);
myBalls[i].yv = random(-5, 5);
myBalls[i].mycolor = int(random(0, 100));
myBalls[i].myseed = int(random(25,100));
}
}
void draw() {
background(0);
for (int i = 0; i < 300; i++) {
myBalls[i].run();
}
}
class Ball
{
float x; //X acis centroid
float y; //Y axis centroid\
float r; // Radius
float xv; //X axis velocity
float yv; //Y axis velocity
int mycolor;
int myseed;
int counter;
void run()
{
drawShape();
x += xv;
y += yv;
yv += 0.4;
if(x < 0 || x > width) {
xv = -xv;
}
else if(y < 0 || y > height) {
yv = -1.1 * yv;
}
if(counter % myseed == 0) {
xv = random(-5,5);
yv = random(-5,5);
}
counter++;
}
void drawShape()
{
smooth();
ellipseMode(CENTER_RADIUS);
noStroke();
fill(mycolor);
ellipse(x,y,r,r);
}
}
You can download it here: sketch_070719a
Tags: _why
Posted by hardwarehank,
Fri Oct 06 13:59:34 UTC 2006
I got featured on
Redhanded.
Apparently, I’m a bike. Probably because of my behavior under the name
o`o in IRC. Sigh, it’s my only claim to fame. :(
Tags: _why
Posted by hardwarehank,
Wed Sep 13 14:52:31 UTC 2006
I wanted to put emoticons into Textile for
Beast, but to do it, I needed to use very
few lines of code since there is a 500LOC limit on Beast. After a long time
debugging, here’s what I came up with:
First, I made a new method in the RedCloth namespace.
class RedCloth
def refs_smiley(text)
text.gsub!(/(\s)~(:P|:D|:O|:o|:S|:\||;\)|:'\(|:\)|:\()/) do |m|
bef,ma = $~[1..2]
filename = ActionController::AbstractRequest.relative_url_root+"/images/emoticons/"+(ma.split(//).collect{|l|l[0]}.join('_'))+".png"
"#{bef}<img src='#{filename}' title='#{ma}' class='smiley' />"
end
end
end
All I’m doing here is some nifty gsubbing with a block. The resultant
replacement expression is the last thing returned by the block. This RegExp
will match any of the possible emoticons I specified as long as they are
preceeded by a ~. This prevents things like :Person from being converted
into :Person. Here is
the post about it with all the emotes I allow. Try it out. While I was at
it, I re-activated tables for Textile in Beast. This was totally necessary. ;)
Then I changed the text format helper in Beast to reflect my new method:
def format_text(text)
RedCloth.new(auto_link(text.to_s)).to_html(:textile,:refs_smiley)
end
The key part here is the options passed to to_html. This allows you to
pick any rules you want for your code generation. I found that when I named
the method smiley, it wouldn’t be called. That’s because there is a
RegExp match that happens when the rule methods are called that matches on
methods that begin with refs_. I think you could get around that
somehow, but I just went with it. The default options that are implicit on a
call of to_html are :markdown,:textile, and as you can see, I left out
markdown. Also, I realized that white_list was causing my generated
tables to be ruined, so I took that out. This might be a little dangerous,
but I’m not too worried at this point. I might have to submit a patch (or
make a modification) to the white_list plugin. The possibilities here are
endless, thanks to _why.
Tags: _why
Posted by hardwarehank,
Sat Sep 02 11:26:02 UTC 2006
Well, I was stumbling today and found OpenDNS. I
was excited to find that I could make it coexist with OpenNIC in my dhclient
configuration. Here’s the resultant line that makes all this magic happen:
prepend domain-name-servers 63.226.12.96, 208.67.222.222, 208.67.220.220;
So now, when I use dhcp to grab an IP, I end up prepending these nameservers
onto my resolv.conf. OpenDNS makes spam sites and domain squatters disappear.
And it makes the average request a lot faster.
Yesterday, bish0p and I sat down and started
work on MyDNS. It turns out that the db structure
isn’t all that bad, so it will be fairly straightforward to build a
Rails/Camping interface for it. I already started one in Camping called
Beacon. I was going to name it ChunkyBeacon, but #camping decided
against that.
In other news, I’m going to leave Fairbanks for a while soon. It will be
exciting to go on this adventure into the real world for four months.
Tags: _why
Posted by hardwarehank,
Fri Aug 25 13:21:03 UTC 2006
Today, I decided I needed a quick way for my friends who run Linux to try ruby. Using _why’s awesome curl implementation of tryruby, here is the ultimate alias for any bashrc:
alias tryruby='sh -c "$(curl -s http://tryruby.hobix.com/try.sh)"'
Tags: _why
Posted by hardwarehank,
Wed Jul 05 21:07:34 UTC 2006
_why made a really sweet HTML parser called Hpricot. This allows you to easily parse a remote document using Open-URI. Here’s how to do it:
require 'rubygems'
require_gem 'hpricot'
require 'open-uri'
puts "Grabbing Page..."
html = open("http://www.amazon.com/gp/product/1844300439/ref=amb_cob_bh_194691301/002-0086113-2532879?n=283155")
puts "Parsing..."
doc = Hpricot.parse(html)
(doc.search("//table//td[@id='prodImageCell']")/:img).each do |link|
p link.attributes
end
{"src"=>"http://ec1.images-amazon.com/images/P/1844300439.01._AA240_SCLZZZZZZZ_V54614147_.jpg", "border"=>"0", "id"=>"prodImage", "height"=>"240", "alt"=>"Cobblers", "width"=>"240"}
ruby -rrubygems -ropen-uri -e "require 'hpricot';(Hpricot.parse(open('http://www.amazon.com/gp/product/1844300439/ref=amb_cob_bh_194691301/002-0086113-2532879?n=283155')).search(\"//table//td[@id='prodImageCell']\")/:img).each {|link| p link.attributes }"
Amazing stuff really. The parser is so amazingly fast. All the time is spent fetching the page, not parsing!
Also, “Sunset, Sunrise” by Razor Ramon is awesome.
Tags: _why
Posted by hardwarehank,
Thu Jun 22 13:14:31 UTC 2006
Using Why’s insane URI require stuff, I revised my sig by making a file called rubysig.txt on modzer0:
$_=[1165125995,541553253,1734811772,543711598,1799381356,1634954081,778396789,545005639,1346849637,2033852464,2016687683,825700673,48];$/="";:c.id2name.hex.times{$/<<78.chr};$/<<99.chr;$\=$_.pack($/);puts$\
and calling it like this:
ruby -ropen-uri -e 'eval(open("http://modzer0.cs.uaf.edu/~hardwarehank/rubysig.txt").read)'
I just made a DNS redirect for the URL at sig.ralree.info so soon it will be this:
ruby -ropen-uri -e 'eval(open("http://sig.ralree.info").read)'
Yay for Why!
Tags: _why