Sunday, 8 November 2009

Quantum Factoring Algorithm

I was just reading about the LCH. It seems to me that the following experiment might be of use: choose a large random number, if it is a factor of a large composite of interest stop, otherwise start the LHC.
Posted by james at 9:34 PM in Tools and Programming

Monday, 12 October 2009

Gentoo versus Ubuntu

At some point, I decided to give Ubuntu Linux a try after several years of using Gentoo. After four months, I ended switching back because I missed the handling of daemons (rc-status), java (java-config), and virtual services. The point of this post is to Ubuntu folks: steal these capabilities from gentoo.
Posted by james at 10:36 PM in Tools and Programming

Monday, 14 September 2009

Drop versus reject

Contemplating the firewall configuration of my home machine, it occurs to me that rejecting packets is likely more secure than dropping them (as to render more difficult IP spoofing).
Posted by james at 10:22 PM in Tools and Programming

Thursday, 20 August 2009

Boolean Parser Combinator in Scala

The title says it all (sort of).
package net.unsyntax.learning.parsercombinator;

import scala.util.parsing.combinator.lexical.StdLexical
import scala.util.parsing.combinator.syntactical.StdTokenParsers

class BooleanParserCombinator(f:String => Boolean) extends StdTokenParsers {
  type Tokens = StdLexical;
  
  val lexical = new StdLexical();
  lexical.delimiters ++= List("(", ")", "&", "|", "!");
  lazy val expr:Parser[Boolean] = flag*("|" ^^^ {(x: Boolean, y: Boolean) => x || y} |
    "&" ^^^ {(x: Boolean, y: Boolean) => x && y}); 
  lazy val flag:Parser[Boolean] = ("(" ~> expr <~ ")" | ident ^^ (f(_)) |
    "!" ~> ident ^^ (!f(_)) | "!" ~> expr ^^ {(x:Boolean) => !x});
  
  def apply(in:String):Boolean = {
    return expr(new lexical.Scanner(in)).get;
  }
}
The test program:

package net.unsyntax.learning.parsercombinator

import scala.collection.immutable.ListSet;

object BooleanParserCombinatorTest {
	val tests = List("true", "false", "!true", "!false",
          "true&false", "true|false", "true|(true&false)",
          "true&(true|false)", "false|!false");

	val eval = new BooleanParserCombinator(_.toBoolean).apply(_);
	def main(args: Array[String]) {
	  
	  for (test <- tests) {
	    println (test +"="+eval(test));
	  }
   	}
}
yields
$ java net.unsyntax.learning.parsercombinator.BooleanParserCombinatorTest
true=true
false=false
!true=false
!false=true
true&false=false
true|false=true
true|(true&false)=true
true&(true|false)=true
false|!false=true
$ 
Posted by james at 10:09 PM in Tools and Programming

Monday, 17 August 2009

Playing with scala

$ scala
Welcome to Scala version 2.7.3final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_14).
Type in expressions to have them evaluated.
Type :help for more information.

scala> def factorial (x:Double):Double = if (x == 0) 1 else x*factorial(x-1);
factorial: (Double)Double

scala> def exp(y:Double):Double = (0.0 /: 1.to(20).map (x => Math.pow(x,y)/factorial(x)))(_+_)
exp: (Double)Double

scala> exp(1);
res0: Double = 2.7182818284590455

scala>
Posted by james at 9:24 PM in Tools and Programming

Tuesday, 17 February 2009

Delicious Login

For some reason, perhaps security, the fine folks at delicious set the autocomplete attribute for the login page to "off" thus disabling the firefox password manager. It drives me loopy. Grease Monkey to the rescue!


// ==UserScript==
// @name           Delicious Login
// @namespace      http://unsyntax.net/
// @description    Enable autologin with delicious
// @include        https://secure.delicious.com/login*
// ==/UserScript==

(function () {
    var inputs=document.getElementsByTagName("input");    
    for (var i=0; i < inputs.length; i++) {
	if (inputs.item(i).getAttribute("autocomplete")) {
	    inputs.item(i).removeAttribute("autocomplete");
	}
    }    
})()
Posted by james at 7:15 PM in Tools and Programming

Thursday, 20 November 2008

IPv6 Yikes

I Just noticed my local internet provider has started giving me an IPv6 address, along with an IPv4 address, over DHCP. Unfortunately, iptables on my Linux machine does not address filtering of IPv6, only of v4. To filter v6 one needs ip6tables (and to start and configure it correctly). Whoops.

I wonder if this could be combinded with DHCP spoofing as a means to bypass firewalls.

Posted by james at 8:38 PM in Tools and Programming

Wednesday, 19 November 2008

Semantic Digital Signatures

A shameless plug for issues that have occupied my (and my coauthors) thoughts as of late.

We discuss the need of addressing, in a uniform way, digital signatures with rich semantics, for enabling increased automation of signature processing. We present a scheme for combining digital signatures with the formal and extensible semantics of the Semantic Web, as a standard layer in applications using digital signatures. We introduce several constructions and processes towards realizing this end, a new class of attack against semantically enabled applications, and measures of avoiding this attack class. Finally, we simplify a few existing processes that use digital signatures by expressing them in terms of semantic signatures.
By: Daniela Bourges-Waldegg, Christian Hoertnagl, James Riordan

Comments especially welcome.

Posted by james at 9:47 PM in Tools and Programming

Wednesday, 17 September 2008

Ruby lambda

I was chatting with a friend yesterday about scripting languages. Ruby has nice lambda functions:
#!/usr/bin/ruby
lambda{|f|f[f,lambda{|x|lambda{||x+=1;}}[1]];}[lambda{|f,g|
lambda{|n|puts(n);f[f,lambda{|h|lambda{||h[h];}}[lambda{|h|
lambda{|f|(f%n==0)?h[h]:f;}[g[]];}]];}[g[]];}];
Posted by james at 1:53 PM in Tools and Programming

Thursday, 21 August 2008

Lambda, the ultimate procrastination

I was chatting with a friend about JavaScript's nice treatment of functions. I got a bit carried away writing an example inspired by such a construction I saw ages ago in Scheme by Kenneth Oksanen. The javascript is executable with rhino:
(function (foo) { return foo(foo,(function (foo) { return function() { return foo+=1;} ;})(1)); })(function (foo, baz) {return (function (prime) 
{print(prime); return foo(foo,(function(foo) {return function () {return foo(foo);};})(function (bar) {return (function(foo) {
return ((foo%prime) ? foo :bar(bar));})(baz());}));})(baz());});
Note that this should not be pasted into a browser as the "print" function has a different meaning in a browser (e.g. send it to a printer versus print it to standard out) and it will throw your browser into a hard to kill loop. I wrapped a version in a web page here which freezes my browser (firefox) for a few seconds but the browser eventually kills the script.
Posted by james at 12:10 PM in Tools and Programming

Wednesday, 6 August 2008

Javascript conventions

A friend made an interesting comment about a recent post that "it's one of those conventions that makes Javascript workable". This got me thinking: when can and when should conventions be enforced within the language? Take, for example, language support of packages: before languages with package support, conventions provided similar functionality albeit in a limited and inconsistent fashion. Requiring package constraints is an improvement.

I have ofen wondered, why do I find Javascript so painful? Based on the language design, I should really like it. I think the answer might be lack of useful constraints within the language which requires the programmer act more as a language designer: both code and conventions but be produced. I am certain that I do not know the complete collection of useful conventions and figuring them out is a rather long and painful process.

This in turn reminded me of reading a collection of essays by Paul Graham. The particular essay praised Lisp for its macro system which allows one to introduce new syntactic features into the language. He argued that a language with more functionality is better than one with less.

While I share his love of lisp and enjoy his writing, I find the argument troublesome. It's a bit as though he argued that 16/64 equals 1/4 because one "can cancel the sixes". I am fine with the conclusion but that argument... woof. Perhaps the easiest way to win a public argument with a mathematician is to make an obvious and universally accepted claim using a bad argument. The mathematician will insist that you are not allowed "to cancel the sixes" while most of the audience will think "but it is 1/4... why is this idiot arguing?".

I think that more featured in a static sense of a language (the code exists and does not change) is not necessarily more powerful in a dynamic sense of a language (code is being written and will continue to change). For example:

  • static typing is less expressive that dynamic typing but enables refactoring,
  • disallowing destructive assignment is less featureful than allowing destructive assignment but enables concurrency,
  • disallowing access to certain resources is limiting but means that untrusted code may be executed safely

Back to topic, the top google hit on Javascript conventions is interesting reading. Do my few readers have other suggestions?

Posted by james at 11:43 AM in Tools and Programming

Thursday, 17 July 2008

Javascript prototypes

As I continue with my firefox extension writing, I wanted to refresh my knowledge of Javascript prototypes. Unfortunately most of the examples that I found were not very good. The normally very good site http://www.w3schools.com/ has an example that doesn't really demonstrate the feature (the result is the same without the prototype line); it also does not have anything to do with math.

The following modification to the w3schools example might be more illustrative:

function employee(name,jobtitle,born)
{
  this.name=name;
  this.jobtitle=jobtitle;
  this.born=born;
}

var fred=new employee("Fred Flintstone","Caveman",1970);
var barney=new employee("Barney Rubble","Caveman",1971);

employee.prototype.salary=19000;
fred.salary=20000;

print("Fred's salary is "+fred.salary);
print("Barney's salary is "+barney.salary);
Posted by james at 11:50 AM in Tools and Programming

Monday, 14 July 2008

Firefox extensions

I have been playing around with writing firefox extensions as of late. One of the difficulties I kept hitting was that testing is difficult inside the browser. For example, a syntax error in javascript seems to prevent any useful messages from being generated (like "syntax error line X in file Y"). I have found it useful then to split my javascript into three categories:

  • One that actually executes logic such as registering functions to events
  • One that dereferences and abstracts functions specific to the brower
  • One that defines, but never executes, the logic that provides most of the functionality

This offers the advantages that files of the last two categories can be syntactically checked by executing the code with a javascript interpreter (such as rhino) and files of the last category can be functionally and interactively tested by writing stubs of the files in the middle category.

Posted by james at 3:29 PM in Tools and Programming

Friday, 23 May 2008

Eclipse, Scala, and Java

I have been giving Scala a try; I mostly like it. While Scala cooperates nicely with Java, the same cannot be said of the Scala plugin for Eclipse. Some how it seems not to find Java classes within the same project. A workable solution is creating two projects using symbolic links for the source directories, one Scala and one Java, which depend on one another.

Posted by james at 10:41 PM in Tools and Programming

Friday, 11 April 2008

Tomcat connection pooling

This morning I decided to switch from my own database connection pooling class to that in tomcat. As with many tomcat issues, figuring out what is happening is not particularly easy. A bit of digging reveals that my servlet was crashing because org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory was not being found. "Easy enough..." I thought "I can just add in to the common libraries". Where is this class defined? That I never figured out. The name is specified in a tomcat constants file which is later referenced as a default in System.getProperties("javax.sql.DataSource.Factory"). Magically, if one adds

  • commons-dbcp.jar
  • commons-collections.jar
  • commons-pool.jar
(the latter two being dependencies of the first .jar file), tomcat seems to figure it out the new factory without even setting "javax.sql.DataSource.Factory".

Posted by james at 5:40 PM in Tools and Programming