Skip to content

Instantly share code, notes, and snippets.

View samskivert's full-sized avatar

Michael Bayne samskivert

View GitHub Profile
//
// RECTANGLE FNS
/** Creates a rect region based on the supplied `start` and `end` locations. A rect region is
* represented as a `Loc` for the start of each line and a number of characters. Note: this
* function does not validate that `start` and `end` are in the buffer or otherwise valid. */
def rectRegion (start :Loc, end :Loc) :Seq[(Loc, Int)] = {
val width = end.col - start.col
val lines = Seq.builder[(Loc, Int)]()
var cur = start ; while (cur.row <= end.row) {
@samskivert
samskivert / logic.lisp
Created December 31, 2015 01:41
Hypothetical game logic rules/scripts
;;
;; Utility functions
;; returns a randomly chosen unit stat
(defun randstat () (pickrand 'hp 'attack))
;; returns a randomly chosen battle unit kind
;; (TODO: base this on all unit kinds that have >0 attack)
(defun randbattler () (pickrand 'strike 'defend 'drone))
> proguard:proguard
[info] Updating {file:/Users/mdb/projects/codex/}codex...
[info] Resolving net.sf.proguard#proguard-base;4.9 ...
[info] Done updating.
[info] Compiling 32 Scala sources to /Users/mdb/projects/codex/target/classes...
[warn] there were 83 deprecation warning(s); re-run with -deprecation for details
[warn] one warning found
[info] ProGuard, version 4.9
[info] Reading program directory [/Users/mdb/projects/codex/target/classes]
[info] Reading program jar [/Users/mdb/.ivy2/local/com.samskivert/samscala/1.0-SNAPSHOT/jars/samscala.jar]
// Say we have a List of names and we would like to find all those names where "am" occurs:
{
// LINQ
// string[] names = { "Sam", "Pamela", "Dave", "Pascal", "Erik" };
// List<string> filteredNames = names.Where(c => c.Contains("am"))
// .ToList();
// Java Streams
// String[] names = {"Sam","Pamela", "Dave", "Pascal", "Erik"};
// List<String> filteredNames = stream(names)
@samskivert
samskivert / gist:742752
Created December 15, 2010 23:06
Readability
case class Command (name :String, callsOtherCode :Boolean)
case class Procedure (name :String, commands :List[Command])
case class Activation (procedure :Procedure, parent :Option[Activation], returnAddress :Int) {
def parentCmdName :Option[String] =
parent map(_.procedure.commands(returnAddress)) filter(_.callsOtherCode) map(_.name)
}
def callStack (act :Activation) :List[String] =
List(act.procedure.name) ++ act.parentCmdName ++ act.parent.map(callStack).flatten
object Euler063 extends EulerApp {
def count (n :Int, p :Int, c :Int) :Int =
if (n == 10) c
else if (BigInt(n).pow(p).toString.length < p) count(n+1, 1, c)
else count(n, p+1, c+1)
def answer = count(1, 1, 0)
}
object Euler062 extends EulerApp {
def search (n :Long, cubes :Map[Long,List[Long]]) :Long = {
val cube = n*n*n
val key = cube.toString.sortWith(_>_).toLong
val perms = cube :: cubes.getOrElse(key, Nil)
if (perms.length == 5) perms.last
else search(n+1, cubes + (key -> perms))
}
def answer = search(1, Map())
}
% gem install jekyll
Fetching: fast-stemmer-1.0.2.gem (100%)
Building native extensions. This could take a while...
Successfully installed fast-stemmer-1.0.2
Fetching: classifier-reborn-2.0.3.gem (100%)
Successfully installed classifier-reborn-2.0.3
Fetching: ffi-1.9.8.gem (100%)
Building native extensions. This could take a while...
Successfully installed ffi-1.9.8
Fetching: rb-inotify-0.9.5.gem (100%)
Dependency Error: Yikes! It looks like you don't have redcarpet or one of its dependencies installed. In order to use Jekyll as currently configured, you'll need to install this gem. The full error message from Ruby is: 'dlopen(/usr/local/Cellar/ruby/2.1.3_1/lib/ruby/gems/2.1.0/extensions/x86_64-darwin-14/2.1.0/redcarpet-3.2.2/redcarpet.bundle, 9): Library not loaded: /usr/local/lib/libruby.2.1.0.dylib Referenced from: /usr/local/Cellar/ruby/2.1.3_1/lib/ruby/gems/2.1.0/extensions/x86_64-darwin-14/2.1.0/redcarpet-3.2.2/redcarpet.bundle Reason: image not found - /usr/local/Cellar/ruby/2.1.3_1/lib/ruby/gems/2.1.0/extensions/x86_64-darwin-14/2.1.0/redcarpet-3.2.2/redcarpet.bundle' If you run into trouble, you can find helpful resources at http://jekyllrb.com/help/!
Conversion error: Jekyll::Converters::Markdown encountered an error while converting 'docs/release/Migrating15to16.md':
redcarpet
ERROR: YOUR SITE COULD NOT BE BUILT:
--------------------------
# NEO4J Version
% spam run codex#java codex.TestCodex
Diagnostics [error=100, mandatory_warning=16]
Extract and store: 15s
30006 defs.
32382 names.
% du -sk neo4j-codex/* | sort -nr
15052 neo4j-codex/neostore.propertystore.db