Skip to content

Instantly share code, notes, and snippets.

View stepancheg's full-sized avatar

Stepan Koltsov stepancheg

View GitHub Profile
import java.io._
import java.nio._
val f = new File("/dev/zero")
val size = 10000
val count = 100000
def readUsingInputStream() {
val is = new FileInputStream(f)
@stepancheg
stepancheg / ManagedSeq.scala
Created November 15, 2009 19:43
ManagedSeq
import scala.collection._
import scala.collection.generic._
import scala.collection.mutable.Builder
trait ManagedResource[+A] { self =>
def acquireFor[R](f: A => R): R
def map[B](g: A => B): ManagedResource[B] = new ManagedResource[B] {
override def acquireFor[R](f: B => R) = {
self.acquireFor(x => f(g(x)))
@stepancheg
stepancheg / gist:233190
Created November 12, 2009 19:05
newline detection
.file "hello.c"
.text
.p2align 4,,15
.globl find_newline
.type find_newline, @function
find_newline:
.LFB3:
xorl %edx, %edx
testq %rsi, %rsi
je .L3
size_t find_newline(const char* ptr, size_t len) {
size_t i = 0;
while (i < len) {
if (ptr[i] == '\n')
return i + 1;
if (ptr[i] == '\r') {
if (i + 1 < len && ptr[i + 1] == '\n')
return i + 2;
else
return i + 1;
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
"
" Author: Alex Naanou
"
" WARNING: The following will kill most indent functionality in vim.
" though you still can use ^F
"
" to install just drop me into your plugin dir.
nnoremap o ^y<home>o<esc>pI
nnoremap O ^y<home>O<esc>pI
@stepancheg
stepancheg / gist:168376
Created August 15, 2009 15:19
Junk — dummy profiler
package scala.tools.nsc
object Junk {
def currentTimeMicros = System.nanoTime / 1000
case class Current(stack: List[String], start: Long)
var current: Option[Current] = None
val map = new scala.collection.mutable.HashMap[String, Long]
@stepancheg
stepancheg / gist:168375
Created August 15, 2009 15:18
PackageLoader.doComplete diff
Index: Global.scala
===================================================================
--- Global.scala (revision 18483)
+++ Global.scala (working copy)
@@ -848,6 +848,7 @@
}
}
for ((sym, file) <- symSource.iterator) resetPackageClass(sym.owner)
+ Junk.printStats()
informTime("total", startTime)
@stepancheg
stepancheg / gist:167566
Created August 14, 2009 01:15
How to convert Scala XML to JDK DOM
object XmlHelpers {
val docBuilder =
javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder()
}
class NodeExtras(n: Node) {
def toJdkNode(doc: org.w3c.dom.Document): org.w3c.dom.Node =
n match {
case Elem(prefix, label, attributes, scope, children @ _*) =>
// XXX: ns
** unknown exception encountered, details follow
** report bug details to http://www.selenic.com/mercurial/bts
** or [email protected]
** Mercurial Distributed SCM (version 1.2)
** Extensions loaded: forest, graphlog, hg-git, hgsubversion, mq, patchbomb
Traceback (most recent call last):
File "/usr/bin/hg", line 27, in ?
mercurial.dispatch.run()
File "/var/lib/python-support/python2.4/mercurial/dispatch.py", line 16, in run
sys.exit(dispatch(sys.argv[1:]))