Skip to content

Instantly share code, notes, and snippets.

View ymnk's full-sized avatar

Atsuhiko Yamanaka ymnk

View GitHub Profile
import java.math.{BigDecimal => BD, MathContext}
import BD.{ZERO, ONE}
/**
* This program will calculate Pi with John Machin[1]'s formula[2].
* This is just a translation from Mr. Kishida's Java implementation[3] to
* Scala one.
*
* [1] http://en.wikipedia.org/wiki/John_Machin
* [2] http://upload.wikimedia.org/math/f/1/5/f15dc3d39c473c4bd718e3a98145da0d.png
import java.math.{BigDecimal => BD, MathContext}
import BD.{ZERO, ONE}
/**
* This program will calculate Pi with John Machin[1]'s formula[2].
* This is just a translation from Mr. Kishida's Java implementation[3] to
* Scala one.
*
* [1] http://en.wikipedia.org/wiki/John_Machin
* [2] http://upload.wikimedia.org/math/f/1/5/f15dc3d39c473c4bd718e3a98145da0d.png
@ymnk
ymnk / pdr.scala
Created November 13, 2008 06:24 — forked from anonymous/pdr.scala
package pdr;
import javax.swing._;
import java.awt._
import java.awt.geom._;
import java.awt.image._
import java.io._
import scala.collection.mutable.ArrayBuffer
import scala.collection.mutable.HashMap
/*
Copyright (c) 2008 ymnk, JCraft,Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
import scala.tools.nsc.{Interpreter, Settings, Global}
import scala.tools.nsc.util.{Position,NoPosition, ShowPickled}
import scala.reflect.generic.{PickleFormat, PickleBuffer}
import scala.tools.nsc.symtab.classfile.{ClassfileParser}
import scala.tools.nsc.io.AbstractFile
import java.io.{OutputStream, PrintStream, ByteArrayOutputStream}
object DumpGenericsSignature {
class MyParser extends ClassfileParser{
/*
Copyright (c) 2008 ymnk, JCraft,Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
import scala.xml.Node
import scala.collection.immutable.Set
import scala.util.Sorting
/**
* This program will demonstrate how to use scala.util.Sorting.
*/
object SortingDemo {
def main(arg:Array[String])={
import java.net.{Authenticator, PasswordAuthentication}
import java.net.{URL, HttpURLConnection}
import scala.xml.{XML, Node}
import scala.collection.mutable.Map
class FriendOrFollow (screen_name:String) {
private val friends_url = "http://twitter.com/statuses/friends/%s.xml"
lazy val friends:Map[String, Node] =
getMap(friends_url.replace("%s", screen_name))
import scala.xml._
import scala.util.parsing.json.JSON
/**
* The XML2JSON object will transform a string in json format to
* a NodeSeq object.
*/
object JSON2XML {
def apply(input:String):NodeSeq = {
import scala.util.parsing.combinator.lexical.StdLexical
import scala.util.parsing.combinator.syntactical.StdTokenParsers
/**
* This program will parse the arithmetic expression defined as follows,
* <exp> ::= <term> | <exp> "+" <term> | <exp> "-" <term>
* <term> ::= <factor> | <term> "*" <factor> | <term> "/" <factor>
* <factor> ::= <n> | "(" <exp> ")"
* , where n is a nonterminal symbol for numbers.
*