SubSonic With Postgres

I decided to attempt to get SubSonic3 to work on Mono using Postgres as the database. I couldn't get it to run on Mono due to incomplete support of Linq, but I did get what I think are meaningful templates for Postgres with ActiveRecord, as of right now though it requires a different provider outside of SubSonic.Core

You can download the entire source here in tar.gz format

12010-08-02 19:52:38.746264

Posted: 5/20/2011 1:05:38 AM

That's weird

Ok, so I decided to go mobile and test EMF meter in other places away from home. I use a laptop so I was concerned things may be slightly weird, but they actually seemed about right..

All images have 10ms between points and record a total of 100 points, and then graphs them.

This is my control: http://tinyurl.com/2ceunxf

Out in the absolute middle of no where(I had no idea where I was since it is currently night). I could not see any power sources and was far away from any homes: http://tinyurl.com/28bso4j

This is the same one, but my car is off: http://tinyurl.com/272spbl

Another of the same one, but my car is off and headlights off(it was scary!): http://tinyurl.com/3yk8mtd

This is one where I'm near houses, but about 50-150 yards from a power line/house: http://tinyurl.com/2uqygqr

Same one as above after turning my car off and headlights off: http://tinyurl.com/35km446

So apparently my car made the results a bit funky, especially on that first one. There was an absolute 0 voltage for about 1/2 a second! That just seems unheard of. I'm pretty sure my car had canceled things out or something though because of the results of the other two graphs.

Also, as you can see, the 60hz wave is very strong apparently in my apartment, where things are relatively waveless when away from a power source. I did this to see how "quiet" the country is as far as EMF. Apparently, it's very quiet compared to in a house because of the 60hz. But, it's not absolutely silent either. I plan on doing this again during the day and seeing if the results are skewed any with the sun out, and also whenever it is storming I plan on doing this some and see if I can capture any lightning.

This means that to test my EMF camera, I will probably have to be somewhere away from power so that my results aren't skewed horribly by the 60hz EMF all around.. 12010-05-01 23:52:15.227511

Tags: old-import
Posted: 5/20/2011 12:52:08 AM

Hey, you got new tables... I hate them

Ok, I'm finally ready to rant about tables. Ok. I guess I have to admit, table aren't the worst thing in the world. Yet, anyway.

The obvious problem is the misuse of tables. For instance, I come across HTML code where it seems as if people were thinking "Hmm. I need something to align. Better use a table" so they end up with markup like this:

<table>
  <tr>
    <td>
      <img src="akitty.jpg" />
    </td>
  </tr>
  <tr>
    <td>
      <img src="abunny.jpg" />
    </td>
  </tr>
</table>

Of course, this is the obvious way to do it, and not:

<!-- or even better, using a block div... -->
<img src="akitty.jpg" />
<br />
<img src="abunny.jpg" />
<br />

No no, the first one is definitely easier to write and read.

So everyone, if anything isn't simple left-to-right stuff, make sure to use a table by defaultĀ©

Up for next week. Aren't you annoyed with websites that don't support unicode!? (insert self shame here) 12010-05-01 18:11:39.062355

Tags: old-import
Posted: 5/20/2011 12:47:58 AM

EMF Analysis

So a while back I had this idea of building a EMF camera so to speak that could take a picture basically of the total EMF in a room or something. A prototype was going to consist of only a 16 pixel(10 bit color) picture but even that is too much without rethinking my original design. (Would probably involve massive amounts of CPUs. 1 for either every 2 or 4 pixels. ATtinys are cheap, but it's cumbersome because of their small RAM)

Anyway though, I analyzed some basic 2 wire data. so here you go: These are really long URLs btw, my Firefox browser handles it, but your crappy browser may not? Who knows. (all made in Google Charts)

Having music playing beside the coiled wire. (flat wire is leading away from speaker

Large(1000 per wire) dataset. 20ms between samplings. Just sitting on my desk

Small graph with 100-per-wire dataset. no delay(about 1ms-2ms latency of the processor) set 12010-04-17 22:28:17.680849

Tags: old-import
Posted: 5/20/2011 12:40:12 AM

Converting PostgreSQL Database to SQL Server

This may be stale or out of date. It was restored from my old blog database

So, at work we had this database in PostgreSQL. Well, we had been trying to keep that and SQL Server up to date, but we got lazy... So SQL Server was pretty massively out of date.

Well, I was really dreading having to go through editing dumped SQL and/or manually writing each line of SQL for the corresponding conversion.. Then this past weekend I found out about ActiveRecords in Ruby on Rails.

Well, it could connect to SQL Server, with a crap load of pain and it could dump from Postgres and it used a Database Agnostic way of representing schemas. So, of course I figured you could easy use this to keep 2 databases in sync. Well, my method only covers from Postgres to SQL Server, but that is because the Foreigner plugin I use doesn't actually support SQL Server. but I hacked it up anyway.

So, basically, just create a regular Postgres Rails project and set the Database.yml and such to the source database. Then, run rake db:schema:dump this will dump the schema to db/schema.rb Copy that file (I actually printed it off so I could have a hard copy :P ) somewhere safe. Also, be sure to setup the [url=http://github.com/matthuhiggins/foreigner]Foreigner[/url] plugin in the initial rails project configuration. I used the Rails 2 method with the Gem because I couldn't get it to actually install as a plugin.

Now, create another Rails project (or use the one you just configured if your lazy), make sure you have ODBC setup and that isql works. and use something like this for the Database.yml

development:
    adapter: sqlserver
    mode: odbc
    dsn: DSNName #Use the DSN name that you setup in ODBC
    username: sa
    password: pass

Now, you should be able to do rake db:version and get a nice version: 0 status report.

Now, copy that schema.rb from the Postgres project into db/ of the new project.

Now for the fun part. You have to hack up Foreigner so that it will actually do the foreign keys for SQL Server. So first, find where the foreigner.rb file is located on your system under the Ruby Gems directory. Now, modify that file(foreigner.rb) Add something like this:

Foreigner.register 'mysql', 'foreigner/connection_adapters/mysql_adapter'
Foreigner.register 'postgresql', 'foreigner/connection_adapters/postgresql_adapter'
Foreigner.register 'sqlserver', 'foreigner/connection_adapters/sqlserver_adapter' #ADD THIS

Ok. we're half way there. under the same directory as foreigner.rb, create a new file foreigner/connection_adapters/sqlserver_adapter.rb and put this in it:

module Foreigner
  module ConnectionAdapters
    module SQLServerAdapter
      include Foreigner::ConnectionAdapters::Sql2003

      def remove_foreign_key(table, options)
        if Hash === options
          foreign_key_name = foreign_key_name(table, options[:column], options)
        else
          foreign_key_name = foreign_key_name(table, "#{options.to_s.singularize}_id")
        end

        execute "ALTER TABLE #{quote_table_name(table)} DROP CONSTRAINT #{quote_column_name(foreign_key_name)}"
      end
    end
  end
end

module ActiveRecord
  module ConnectionAdapters
    SQLServerAdapter.class_eval do
      include Foreigner::ConnectionAdapters::SQLServerAdapter
    end
  end
end

If you look over in the Postgres Adapter, you'll see that I copied most everything straight from it, and I left out the foreign_keys property, so you can't dump the foreign key schema from a SQL Server database.

Now, you should be able to do

rake db:reset --trace

and it should all work. Verify that it adds the foreign keys... Now a special note. Because of the weirdness of the ODBC, you can't destroy a database. So db:drop does nothing. So, if you need to restore this again because something messed up or whatever, you will have to manually drop and create the empty database. And I'm not sure that Migrations will work. I haven't actually tried them. I think they may work as long as you don't need to delete any foreign keys, but who knows..

So, if you want to quickly convert a Postgres database to SQL Server and do it without $1000+ tools, then this is the way. Good luck! (especially with stupid ODBC!!! grr)12010-04-07 18:35:14.168026

Tags: old-import
Posted: 5/20/2011 12:37:05 AM

Softraid fun!

Note: This was imported from my old blog. This "tutorial" may be stale. Be prepared for differences in newer version of OpenBSD. This was made from 4.6

So I've been messing around recently with the softraid implementation in OpenBSD.. I've done this once before configured for RAID 0, but one of the drives went bad..

In case you aren't aware(as I wasn't without a bit of thinking) you can do softraid experiments with only 1 drive(though it's a bit silly) by creating multiple RAID disklabels or do something useful with 2 drives. I'll use RAID1 as an example. Also, you can install OpenBSD (4.6 at least) straight onto the RAID psuedo-drive..

I'll assume you have wd0 and wd1 for drives.

Boot up the OpenBSD CD and then at the install prompt, goto the shell.

fdisk the disks

# fdisk -iy wd0
# fdisk -iy wd1

Now do the disk label. Here, you have make a decision for how much space you want in / I personally went a bit over and used 100M because I plan on putting some emergency software there in case a RAID chunk goes down.

Do the following replacing X with each drive number. (so do this multiple times)

# disklabel -E wdX
> z
> a
partition: [a] <enter>
offset: [<some number>] <enter>
size: [<some number>] 100M
FS type: [4.2 BSD] <enter>
> a
partition [b] d
offset: [<some number>] <enter>
size: [<some number>] <enter>
FS type: [4.2 bSD] RAID
> w
> q

Now for the actual RAID configuration..

# bioctl -c 1 -l /dev/wd0d,/dev/wd1d softraid0
<blue dmesg text outputted>

Make sure to note what sd device is created as told by the blue text.

Note the number after -c is the RAID level, so you can try one of the other RAID levels if you wish.

Now we need to go back to the install..

# install

Do all the install stuff, and then when you get to "choose the root disk" choose wd0.

when configuring the disklabel all you have to do is

> n a
mount point: /
> w
> q

So now you got your root disk. Now time to use RAID for everything else. When it asks you if you want to initialize other disks, choose the sd device that bioctl created. Usually it should be the highest number of sd device.

You'll have to write a new MBR for the device, so just choose Use Whole Disk and then at disk label, just label everything as normal except for partition-a doesn't get configured as / .

Now you should be able to run everything as normal and you'll be using whatever RAID level you chose.. Have fun! Maybe in the future OpenBSD will get support for automated recovery of failed RAID 1, 4, and 5 levels... There is RAIDFrame, but I haven't bothered myself enough to check into it.. If I do I'll probably write up something here.. 12010-03-14 04:02:11.123145

Posted: 5/20/2011 12:26:19 AM

TL Brainstorming

Ok, I think I know how the implementation is going to work now.. hard to explain, but it will be either 2 or 3 passes. I'm not going to care about speed of translation at this point... If 2 passes, it will be like this:

  1. Preprocess(port the preprocessor of jfbuild[which was also ported to a project at my work])
  2. Read into trees to describe actions. [front-end]
  3. (non-parsing) Write out translation. [back-end]

A bit of brainstorming about how it should work:

//implied?
var x="hi";
var y=x (!=null && .length>0); //Anywhere there is a missing variable, x is implied to be the target.
y=x (!=null && somefunction()); //this can be ambiguous for in function arguments though, so that sucks.

//hybrid of both implying and explicitly saying it
y=x (!=null && somefunction(#)); //now the # gets substituted for x.

x=if (0==0) likely{
  puts("this is likely to happen");
  10;
}
//x is now equal to 10

x=[0,1,2,3];
x$=1-x@;
//x==[1,0,-1,-2]

12010-02-24 09:55:08.428546

Tags: old-import
Posted: 5/20/2011 12:21:36 AM

More TL

This is what I posted to xkcd which helped to clear my thoughts on the language:

I have recently been thinking about a very DRYable language that can also very clearly express your ideas in programming, and thus being able to make optimizations that would otherwise be impossible...

//comment. It is both statically and dynamically typed.
var x;
var int y;
x=0;
y=10;
x+=y;

if x (<20 && > 5)  probably{
  puts("This will probably execute, as told to the compiler");
}else{
  puts("This probably won't execute);
}

x=[0,1,2,3];
//y=x; would yield a type error
x$+=1; //this will add 1 to every element in the array

if x$ (>0 && <3) { //this will check every value in x for this condition
  puts("x: "+x@+" "); //x@ is the current value of x(be it for this thread of whatever)
}
//this will print either x: 1 x:2 or x:2 x:1
//Note, the implementation is allowed to create a new thread for any block, so this can be made implicitly multi-threading

x$=0; //x now equals [0,0,0,0]
x=[0,1,2,3];
while(x$<5){
  x@+=1;
}
//x is now equal to [5,5,5,5]
//and the loop created 4 threads(implementation defined) to execute that loop with all of those values
//it is the equivalent of doing this:
var i;
for(i=0;i<x.count);i++){
  while(x[i]<5){
    x[i]+=1;
  }
}
//except for in the last one, the compiler isn't sure it can actually optimize it or not

2010-02-22 20:01:49.715021

Tags: old-import
Posted: 5/20/2011 12:20:02 AM

The TL

Well, I've been thinking about a new weird project.. TL. the Translation Language.

Basically, it is a language designed to be a translated to another high level language. I'm thinking it should be multi-paradigm, so that functional programming can be compiled from a C compiler..

But anyway, I'm thinking it should be statically typed, even though I love dynamically typed languages.. I'm thinking of making a proof of concept of it in Ruby, and then making it capable of translating to C and Ruby. And for proof of concept, ignore complexities such as OOP.

I'm also thinking it should be as high level as possible while still being practical. Such as including a few more "obscure" features such as syntactical vector/array operations so that every operation that can be done on a scalar value can also be done on arrays.

For instance

x=[0,1,2,3];
x$+=10; // => [10,11,12,13] // the $ means to operate on all values of the array
x$=0; // => [0,0,0,0]
x=[0,1,2,3];
if x$ (<3 && >1){ //Allows extreme short-cutting so that you only specify the variable once.  
  puts("value: "+x@+" ");
}
//outputs: value: 2 value: 3
//Note, technically, it could output 3 and then 2. The order is implementation defined and could be executed in parallel. 

idk, I'll have more about this later, it's 1:22am and I'm quite tired.. 12010-02-21 02:23:02.622777

Tags: old-import
Posted: 5/20/2011 12:17:44 AM

Untitled Ruby Thing

Well, I've finally succeeded in creating something that doesn't exist that I wanted by programming. I have created a simplistic little Ruby preprocessor which enables Ruby to be used in web pages similar to PHP. Now of course, there isn't all of PHPs fancy cookie and other such functions.. In fact, there isn't actually an API at the moment. But here is how it roughly looks

<html>
<head>
</head>
<body>
<??rb
  @content+="This was generated by Ruby";
??>
</body>
</head>
</html>

I'll have more info and a SVN repo up later on.. 12010-02-17 22:44:18.592505

Tags: old-import
Posted: 5/20/2011 12:16:23 AM