Skip to content

Instantly share code, notes, and snippets.

View twopoint718's full-sized avatar
yo

Christopher Wilson twopoint718

yo
View GitHub Profile
;; slow because appending to a list means that
;; we have to traverse it over and over again
(defun my-rev-1 (lst)
(if (null lst)
'()
(append (my-rev-1 (cdr lst)) (list (car lst)))))
;; better because we use an empty list that we can
;; cons onto the front of (which is fast)
;; "labels" is a way to make a private recursive
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head><title>Alignment Test</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
<style type="text/css">
.threequarters { position: absolute; left: 75%; border: solid 1px; }
</style>
</head>
<body>
import java.awt.Container; //import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.GridLayout;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class PrintArray
{
public static void main(String[] args)
{
// the basics of printing a 2d array
int[][] a = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
for (int i = 0; i < a.length; i++) {
int[] currRow = a[i];
for (int j = 0; j < currRow.length; j++) {
@twopoint718
twopoint718 / gist:125111
Created June 7, 2009 02:31
Minimal "popup" example
import javax.swing.JFrame;
import javax.swing.JLabel;
public class frame
{
public static void main(String[] args)
{
JFrame f = new JFrame();
f.add(new JLabel("This is a window."));
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
@twopoint718
twopoint718 / gist:125913
Created June 8, 2009 16:22
estimate Euler's constant
public class e
{
public static void main(String[] args)
{
int iterations = Integer.parseInt(args[0]);
double result = 0;
for (int i = 0; i < iterations; i++)
result = result + 1.0 / fact(i);
System.out.println("e estimated with " + iterations + " terms: " +
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<script type="text/javascript">alert('Hello');</script>
</html>
@twopoint718
twopoint718 / gist:128250
Created June 11, 2009 21:33
HashMap w/ String and integer key
import java.util.*;
public class FooMap
{
public static void main(String[] args)
{
HashMap<String,String> data =
new HashMap<String,String>();
String k1 = "A" + 1;
@twopoint718
twopoint718 / gist:132981
Created June 20, 2009 01:02
multiplication table in C
#include <stdio.h>
#include <stdlib.h>
/* a simple multiplication table */
int main()
{
char *cp;
char buffer[256];
printf("Enter a number:\n");
@twopoint718
twopoint718 / multtab.clj
Created June 20, 2009 01:30
multiplication table in Clojure
(defn multtab [n]
(for [row (range n) col (range n)]
(* (inc row) (inc col))))
;; reasonably nicely formatted
(defn main [n]
(let [width (int (Math/ceil (/ (Math/log (* n n)) (Math/log 10))))
digit-str (str "%" (inc width) "d")]
(doseq [row (partition n (multtab n))]
(let [formatted-row (map #(format digit-str %) row)]