When you are in a shell in Linux, you may be led to believe you are in directory
xyz
but might actually be in directorypqr
.
In a terminal,
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 |
#!/usr/bin/env python | |
# -*- coding: utf8 -*- | |
from flask import Flask, redirect, url_for | |
from markdown import markdown | |
import os | |
import re | |
# create the app | |
# TODO: load config/template from files, with fallbacks |
import java.util.Arrays | |
abstract class Sorter { | |
def sorted(a: Array[Int]): Array[Int] | |
} | |
object SimpleSorter extends Sorter { | |
def sorted(a: Array[Int]) = { | |
Arrays.sort(a) | |
a |
var BASE64_MARKER = ';base64,'; | |
function convertDataURIToBinary(dataURI) { | |
var base64Index = dataURI.indexOf(BASE64_MARKER) + BASE64_MARKER.length; | |
var base64 = dataURI.substring(base64Index); | |
var raw = window.atob(base64); | |
var rawLength = raw.length; | |
var array = new Uint8Array(new ArrayBuffer(rawLength)); | |
for(i = 0; i < rawLength; i++) { |
trait Enum { //DIY enum type | |
import java.util.concurrent.atomic.AtomicReference //Concurrency paranoia | |
type EnumVal <: Value //This is a type that needs to be found in the implementing class | |
private val _values = new AtomicReference(Vector[EnumVal]()) //Stores our enum values | |
//Adds an EnumVal to our storage, uses CCAS to make sure it's thread safe, returns the ordinal | |
private final def addEnumVal(newVal: EnumVal): Int = { import _values.{get, compareAndSet => CAS} | |
val oldVec = get |
import java.awt.event.MouseEvent; | |
import java.awt.event.MouseMotionListener; | |
import javax.swing.JFrame; | |
import com.panayotis.gnuplot.JavaPlot; | |
import com.panayotis.gnuplot.swing.JPlot; | |
// include JavaPlot.jar from this site to your classpath | |
// http://gnujavaplot.sourceforge.net/JavaPlot/About.html |
/* | |
Copyright 2012-2021 Viktor Klang | |
Licensed under the Apache License, Version 2.0 (the "License"); | |
you may not use this file except in compliance with the License. | |
You may obtain a copy of the License at | |
http://www.apache.org/licenses/LICENSE-2.0 | |
Unless required by applicable law or agreed to in writing, software |
val n = 9 | |
val s = Math.sqrt(n).toInt | |
type Board = IndexedSeq[IndexedSeq[Int]] | |
def solve(board: Board, cell: Int = 0): Option[Board] = (cell%n, cell/n) match { | |
case (r, `n`) => Some(board) | |
case (r, c) if board(r)(c) > 0 => solve(board, cell + 1) | |
case (r, c) => | |
def guess(x: Int) = solve(board.updated(r, board(r).updated(c, x)), cell + 1) | |
val used = board.indices.flatMap(i => Seq(board(r)(i), board(i)(c), board(s*(r/s) + i/s)(s*(c/s) + i%s))) |
#!/bin/bash | |
display_usage() { | |
echo -e "\nUsage:\n`basename $0` -p [package] -n [dbname] \n" | |
} | |
# if less than two arguments supplied, display usage | |
if [ $# -le 2 ] | |
then | |
display_usage |