This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns streams.core | |
(:require [clojure.java.io :as io])) | |
(def END (Object.)) | |
(defprotocol Stream | |
(with-generator [_ callback] | |
"Should call callback with a generator function, finally closing any | |
resources associated with the stream after the callback returns. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'optparse' | |
OPTIONS = {} | |
PARSER = OptionParser.new do |opts| | |
opts.banner = "Usage: #{$0} [OPTIONS] INPUT_FILE [HOTKEY OUTPUT_FILE]..." | |
opts.separator(<<END | |
#{$0} -- ultra-basic console-based multiclass text annotation tool |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from numpy.lib.stride_tricks import as_strided | |
def ngrams_via_striding(array, order): | |
itemsize = array.itemsize | |
assert array.strides == (itemsize,) | |
return as_strided(array, (max(array.size + 1 - order, 0), order), (itemsize, itemsize)) | |
In [71]: a = numpy.arange(10) | |
In [72]: ngrams_via_striding(a, 4) | |
Out[72]: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Drop me a line if you wanna see this as a proper merb plugin. | |
class Merb::Controller | |
ITEM_RANGE = /^items=(\d+)-(\d+)$/ | |
RANGE = /^(\d+)-(\d+)$/ | |
# Displays a collection resource (using Merb's display method) while supporting requests for sub-ranges of items in a RESTful fashion. | |
# This supports a subset of the HTTP/1.1 spec for content ranges, using a custom range unit 'items'. eg: | |
# GET /collection HTTP/1.1 | |
# Range: items 10-20 |
OlderNewer