Skip to content

Instantly share code, notes, and snippets.

View mahata's full-sized avatar
💭
On parenting...

Yasunori MAHATA mahata

💭
On parenting...
View GitHub Profile
@mahata
mahata / 8.7.cpp
Created September 29, 2011 05:01
C++ Primer 8.7
#include <iostream>
template <typename T> // template A
T ShowArray(T arr[], int n);
template <typename T> // template B
double ShowArray(T * arr[], int n);
struct debts
{
@mahata
mahata / hs-dummy-part3.php
Created October 7, 2011 01:25
hs-dummy-part3.php
<?php
interface WorkerInterface
{
public function work($job);
}
abstract class Worker implements WorkerInterface
{
private $queue_info;
@mahata
mahata / hs-dummy-part4.php
Created October 7, 2011 05:04
hs-dummy-part4.php
<?php
interface Json
{
public function getJson();
}
abstract Class BaseData implements Json {}
class TwitterData extends BaseData
@mahata
mahata / 2.10-1.py
Created October 21, 2011 21:30
An Introduction to Computer Science Using Python 2.10-1
import unittest
class Test(unittest.TestCase):
def test_answer_a(self):
self.assertEqual(9 - 3, 6)
def test_answer_b(self):
self.assertEqual(9 - 3, 6)
def test_answer_c(self):
@mahata
mahata / 2.10-3.py
Created October 22, 2011 17:46
An Introduction to Computer Science Using Python 2.10-3
#!/usr/bin/env python
temp = 24
temp = temp * 1.8 + 32
print "result: ", str(temp)
@mahata
mahata / 2.10-4.py
Created October 22, 2011 17:56
An Introduction to Computer Science Using Python 2.10-4
#!/usr/bin/env python
x = 1.5
y = 4
x = x + y
print "x = ", str(x), ", y = ", str(y) # x = 5.5 , y = 4
@mahata
mahata / 2.10-5.py
Created October 22, 2011 20:20
An Introduction to Computer Science Using Python 2.10-5
#!/usr/bin/env python
x = 3
x += x - x
print "x = ", str(x) # "x = 3"
@mahata
mahata / test.py
Created October 23, 2011 06:16
Language Implementation Pattern - Homogeneous AST - Python (test.py)
import token
import ast
def main():
plus = token.Token(token.Token.PLUS, "+")
one = token.Token(token.Token.INT, "1")
two = token.Token(token.Token.INT, "2")
root = ast.AST(plus)
root.addChild(ast.AST(one))
root.addChild(ast.AST(two))
@mahata
mahata / ast.py
Created October 23, 2011 06:17
Language Implementation Pattern - Homogeneous AST - Python (ast.py)
import token
class AST:
def __init__(self, *args):
self.children = []
if 0 == len(args):
self.token = None
elif 1 == len(args):
if (isinstance(args[0], token.Token)):
self.token = args[0]
@mahata
mahata / token.py
Created October 23, 2011 06:18
Language Implementation Pattern - Homogeneous AST - Python (token.py)
class Token:
INVALID_TOKEN_TYPE = 0
PLUS = 1
INT = 2
def __init__(self, *args):
if 1 == len(args):
self.type = args[0]
elif 2 == len(args):
self.type = args[0]
self.text = args[1]