Skip to content

Instantly share code, notes, and snippets.

View ishikawa's full-sized avatar
🏠
Working from home

Takanori Ishikawa ishikawa

🏠
Working from home
View GitHub Profile
@ishikawa
ishikawa / v8_simple_shell.cpp
Created September 3, 2008 08:29
The simplest shell program for v8 javascript engine
#include <iostream>
#include <sstream>
#include <v8.h>
using namespace v8;
int main(int argc, const char **argv) {
// Create a scope and environment
HandleScope scope;
Handle<Context> context = Context::New();
# Programming Pearls: column 14
class Heaps(object):
"""
>>> h = Heaps()
>>> len(h)
0
>>> h.extend([12, 20, 15, 3, 13, 23])
>>> len(h)
6
@ishikawa
ishikawa / BinaryHeap.java
Created September 10, 2008 04:01
BinaryHeap
import java.util.NoSuchElementException;
/**
* A binary heap is a heap data structure create using a binary tree.
*
* @author Takanori Ishikawa <takanori.ishikawa@gmail.com>
*/
public class BinaryHeap<E extends Comparable<E>> {
private E[] items;
/**
* Heapsort (method) is a comparison-based sorting algorithm,
* and is part of the selection sort family. Although somewhat
* slower in practice on most machines than a good implementation of
* quicksort, it has the advantage of a worst-case Θ(n log n) runtime.
* Heapsort is an in-place algorithm, but is not a stable sort.
*
* @author ishikawa
*
@ishikawa
ishikawa / LinkedList.java
Created September 11, 2008 09:23
LinkedList
package org.metareal;
import java.util.NoSuchElementException;
public class LinkedList <E> {
private final Node<E> head;
private Node<E> tail;
public LinkedList() {
@ishikawa
ishikawa / Queue.java
Created September 11, 2008 09:58
Queue
/**
* http://en.wikipedia.org/wiki/Queue_(data_structure)
*/
public class Queue <E> {
private LinkedList<E> elements = new LinkedList<E>();
public int size() { return elements.size(); }
public boolean isEmpty() { return elements.isEmpty(); }
public E front() { return elements.get(0); }
public E pop() { return elements.removeFirst(); }
@ishikawa
ishikawa / Stack.java
Created September 11, 2008 10:05
Stack
/**
* http://en.wikipedia.org/wiki/Stack_(data_structure)
*/
public class Stack <E> {
private LinkedList<E> elements = new LinkedList<E>();
public int size() { return elements.size(); }
public boolean isEmpty() { return elements.isEmpty(); }
public E top() { return elements.get(0); }
public E pop() { return elements.removeFirst(); }
@ishikawa
ishikawa / GraphSearchAlgorithm.java
Created September 11, 2008 16:47
Graph: BFS and DFS
package org.metareal.graph;
import org.metareal.LinkedList;
import org.metareal.Queue;
import org.metareal.Stack;
public class GraphSearchAlgorithm {
private final LinkedList<Integer>[] vertices;
@ishikawa
ishikawa / binary_search.c
Created September 12, 2008 08:15
Programming Pearls 2nd Edition: Column 5: Binary Search
/*
* Programming Pearls 2nd Edition
* Column 5: Binary Search
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <assert.h>
@ishikawa
ishikawa / compile_python_source.py
Created September 21, 2008 04:01
Using os.spawnv to run and compile files with or without optimization
def compile_python_source(filepath, optimization=False):
"""
Compile a source file to byte-code and write out
the byte-code cache file. The source code is loaded
from the file name *filepath*. The byte-code is cached
in the normal manner (*filepath* + 'c' or 'o' if
optimization is enabled).
"""
from os import spawnv
from sys import executable, platform