Archive for category Computer Science

Reading websites with PHP

Use cURL.

References

No Comments

LAPACK

$ cp make.inc.example make.inc
$ make blaslib testing
$ make

http://icl.cs.utk.edu/lapack-forum/archives/lapack/msg00046.html

add current directory to library search path

$ gcc -L . -lm -llpack file.c -o executable_file

No Comments

Mac OSX getline broken

It seems that getline() is broken in debug mode in OS X (gcc 4.2).

C++ Debug builds broke in Snow Leopard X-Code

Xcode STL C++ Debug compile error

hmmm… I guess nobody uses xcode for c++.

Work around? use gcc 4.0 instead

No Comments

Stacking a Texas Hold’em Deck

I saw an interesting trick on Scam School. It turns out that you can stack a deck in such a way that the dealer always wins no matter how you cut the deck. This deck was found by Ben Joffe and detailed here.

No Comments

Java and 16 bit sound

Here’s the same sound code, but for 16 bit sound instead of 8 bit sound. So, the number of bits tells you how high your signal to noise is. Each bit is about 6 dB, so 16 bits, means 96 dB is about as good as you going to get for a noise level off your sound. If you can keep your noise level below 96 dB, then you can enjoy the full dynamic range of your sound.

import javax.sound.sampled.*;
import java.lang.Math.*;

public class tonegenerator{
    public static void main (String args[]){
	float sampleRate = 44100;
	int sampleSizeInBits = 16;
	int channels = 1;
	boolean signed = true;
	boolean bigEndian = true;
	int offset = 0;
	int bufferSize = 44100*1*2;
	byte[] data = new byte[bufferSize];
	byte ci = 0;
	short s;
	for (int ni = 0; ni < bufferSize/2; ni ++){
		s = (short)(32767*Math.sin(2*Math.PI*ni*1000/44100));
		data[2*ni] =  (byte)(((0xff << 8 ) & s) >> 8);
		data[2*ni+1] = (byte)((0xff  & s));
	}
	try{
	    Clip clip = AudioSystem.getClip();
	    clip.open(new AudioFormat(sampleRate,
				  sampleSizeInBits,
					    channels,
					    signed,
				 bigEndian), data, offset, bufferSize );
		clip.start( );
	}
	catch(Exception e){
	}
    }
}

No Comments

Sound in Java

Here’s a simple java program that should generate A440.

tonegenerator.java

import javax.sound.sampled.*;
import java.lang.Math.*;

public class tonegenerator{
    public static void main (String args[]){
	float sampleRate = 44100;
	int sampleSizeInBits = 8;
	int channels = 1;
	boolean signed = true;
	boolean bigEndian = true;
	int offset = 0;
	int bufferSize = 44100*1;
	byte[] data = new byte[bufferSize];
	byte ci = 0;
	for (int ni = 0; ni < bufferSize; ni ++)
		   data[ni] = (byte)(127*Math.sin(2*Math.PI*ni*440/44100));
	try{
	    Clip clip = AudioSystem.getClip();
	    clip.open(new AudioFormat(sampleRate,
				  sampleSizeInBits,
					    channels,
					    signed,
				 bigEndian), data, offset, bufferSize );
		clip.start( );
	}
	catch(Exception e){
	}
    }
}

No Comments

Command line java

It’s been a while since I’ve touched java. I’d figure I’d not use an IDE and just do it from the command line.

HelloWorld.java

public class HelloWorld
{
  public static void main(String[] args)
  {
    System.out.println("Hello World");
  }
}

$ javac HelloWorld.java

$ java HellowWorld

No Comments

ICC Profile Creation Tool

Time to outline the requirements of my ICC Profile Creation Tool.

I’m most likely going to write this in Java for portability. It doesn’t have to be fast.

Milestones and Tasks

  • Read ICC Profile for Costco printer
  • Write back ICC Profile for Costco printer
  • Find ICC Profile for scanner
  • Calculate ICC Profile for scanner from calibrated values and scanned values
  • Write ICC Profile for scanner
  • Test ICC Profile

No Comments

Windows 7 Impressions

I installed the RTM version of Windows 7 Professional. The installation was smooth and fast, but after I starting installing applications, things firefox crashing and I got some file system errors from applications I downloaded. Eventually I remembered I installed some bad RAM into the computer. Thankfully, I was able to determine which of the two sticks was bad with Memtest86+. After that, I have to say that I like Windows 7, but I don’t use it in day to day operations.

No Comments

Quaternion

I don’t respect any 3D graphics engine that doesn’t use quaternions. They are the best thing to happen to rotations since Euler. Instead of applying rotations to the mesh, I apply a rotation to the existing rotation, which just means calculating the new quaternion. If I apply the rotation to the mesh, the mesh can eventually get screwed up. Objects moving in 3D space go from on quaternion to another instead of having rotations applied to them. This makes the quaternion more of a state variable. Quaternions are awesome, because they make thing so much easier.

No Comments