Skip to content

Instantly share code, notes, and snippets.

@ArtemGr
ArtemGr / jdo-derby-exception.scala
Created April 14, 2009 16:01
Derby via JDO bug.
package fastcms.betdvxq4;
// NO_AUTO_CLASS
import javax.jdo.annotations._
@PersistenceCapable {val identityType = IdentityType.APPLICATION}
class Persistent {@PrimaryKey var name: String = null; var value: String = null}
@PersistenceAware
class main (_tr: ru.glim.cache.Trappings) {
val JDO_FACTORY = withCL {
@ArtemGr
ArtemGr / trace.txt
Created April 15, 2009 07:46
Derby stack trace, third attempt
Caused by: java.sql.SQLException: Column 'PARAM1' already exists.
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExceptionFactory.java:45)
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(SQLExceptionFactory40.java:119)
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(SQLExceptionFactory40.java:70)
... 105 more
Caused by: ERROR X0Y68: Column 'PARAM1' already exists.
at org.apache.derby.iapi.error.StandardException.newException(StandardException.java:303)
at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.duplicateDescriptorException(DataDictionaryImpl.java:1678)
at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.addDescriptor(DataDictionaryImpl.java:1662)
at org.apache.derby.impl.sql.catalog.DataDictionaryImpl.addSPSParams(DataDictionaryImpl.java:3682)
@ArtemGr
ArtemGr / Speed.scala
Created April 17, 2009 09:27
Neodatis micro-benchmark
object Speed {
object cpuSpeed {
val mf = java.lang.management.ManagementFactory.getThreadMXBean
assert (mf.isCurrentThreadCpuTimeSupported)
mf.setThreadCpuTimeEnabled (true)
}
/**
* Run <code>fun</code> for some time and return <i>operations per second</i>.<br>
* The time is measured using thread CPU time counter.
org.neodatis.odb.ODBRuntimeException:
NeoDatis has thrown an Exception
Version=1.9-rc4, Build=514, Date=24-03-2009-23-32-32, Thread=643444394@qtp0-33
10:Internal error : in getObjectInfoInternal
at org.neodatis.odb.impl.core.layers.layer1.introspector.LocalObjectIntrospector.getObjectInfoInternal(LocalObjectIntrospector.java:297)
at org.neodatis.odb.impl.core.layers.layer1.introspector.LocalObjectIntrospector.getObjectInfo(LocalObjectIntrospector.java:111)
at org.neodatis.odb.impl.core.layers.layer1.introspector.LocalObjectIntrospector.getMetaRepresentation(LocalObjectIntrospector.java:96)
at org.neodatis.odb.core.layers.layer3.engine.AbstractStorageEngine.internalStore(AbstractStorageEngine.java:503)
at org.neodatis.odb.core.layers.layer3.engine.AbstractStorageEngine.store(AbstractStorageEngine.java:397)
at org.neodatis.odb.core.layers.layer3.engine.AbstractStorageEngine.store(AbstractStorageEngine.java:379)
@ArtemGr
ArtemGr / VariableLengthInteger.scala
Created May 12, 2009 11:36
VariableLengthInteger
/** Format should be compatible with the one described in http://www.dlugosz.com/ZIP2/VLI.html,
* although we currently use and support only the first "0", "10" and "11" selectors. */
object VariableLengthInteger {
/** Encodes an unsigned integer with a value up to 134217727.
* Returns the position in the "out" array directly after the encoded integer. */
def encodeInt (num: Int, out: Array[Byte], pos: Int): Int = {
if (num < 0) throw new Exception ("Signed integers are not supported.")
else if (num <= 127) {out(pos) = num.toByte; pos + 1}
// Integer.toString (Integer.parseInt ("10000000", 2), 16) == "80"
else if (num <= 16383) {out(pos) = (0x80 + (num >>> 8)).toByte; out(pos+1) = (num & 0xFF).toByte; pos + 2}
@ArtemGr
ArtemGr / alternative, using regex
Created May 21, 2009 16:29
CSV parser in Scala
val pattern = java.util.regex.Pattern.compile ("""(?xs) ("(.*?)"|) ; ("(.*?)"|) (?: \r?\n | \z ) """)
val matcher = pattern.matcher (input)
while (matcher.find) {
val col1 = matcher.group (2)
val col2 = matcher.group (4)
// ...
}
export LANG=en_US.UTF-8; export LANGUAGE=
apt-get install build-essential zlib1g-dev libfuse-dev libaio-dev scons mercurial
hg clone http://www.wizy.org/mercurial/zfs-fuse/trunk
cd trunk/src/
scons install
zfs-fuze # Will start the ZFS daemon.
zpool import # To see what pools we have around.
zpool import -R /mnt -f tank # Where "tank" is the name of the pool.
# Mount the root filesystem (if not already mounted! depends on whether the legacy mode is used for root filesystem!).
@ArtemGr
ArtemGr / GAE - openidLogin.scala
Created October 15, 2009 10:46
OpenID login example; GAE and dyuproject.
package grond.actions
import javax.servlet.http.HttpServletRequest
import com.dyuproject.openid.{RelyingParty, OpenIdUser}
import com.dyuproject.openid.ext.{SRegExtension, AxSchemaExtension}
import com.dyuproject.util.http.UrlEncodedParameterMap
import grond.UserException, grond.model._
/** Perform the OpenID login using the identifier submitted in "openid_identifier".<br>
* If login was successfull, then openidLogin.getAuthenticatedUser will start returning
* the user currently logged in. */
@ArtemGr
ArtemGr / GAE JDO serialized bug.scala
Created October 16, 2009 14:56
GAE JDO serialized versus JSON
import java.lang.{Long => JLong, Integer => JInteger, Double => JDouble}
import java.util.{Map => JMap, HashMap => JHashMap, List => JList, LinkedList => JLinkedList}
import javax.jdo.annotations._
import scala.collection.jcl.Conversions._
/**
* This class tracks all the ratings of a single doctor
* (the doctor is identified by country-region-firstName-lastName).
*/
@PersistenceCapable{val identityType = IdentityType.APPLICATION, val detachable = "true"}
@ArtemGr
ArtemGr / velocity.scala
Created November 21, 2009 16:08
Here's how we use Velocity under GAE.
import java.io.{File, FileInputStream}
import java.util.{Collections, Map, HashMap}
import org.apache.commons.collections.map.{ReferenceMap, AbstractReferenceMap}
import org.apache.velocity.app.VelocityEngine, org.apache.velocity.runtime.resource.{Resource, ResourceManager}
import org.apache.velocity.runtime.resource.loader.ResourceLoader
import org.apache.velocity.exception.ResourceNotFoundException
import org.apache.velocity.runtime.{RuntimeConstants, RuntimeServices}, org.apache.velocity.runtime.log.LogSystem
import org.apache.velocity.Template, org.apache.velocity.VelocityContext
class VelocityResourceManager extends ResourceManager {