Skip to content

Instantly share code, notes, and snippets.

View hammett's full-sized avatar

hamilton verissimo hammett

View GitHub Profile
{
"rust.mode": "legacy",
"rust.rustup": {
// "toolchain": "stable-x86_64-pc-windows-msvc"
"toolchain": "stable-x86_64-pc-windows-gnu"
},
"editor.renderWhitespace": "none"
}
@hammett
hammett / main.rs
Created July 30, 2017 19:20
rust experiment: dumb reverse index
fn main() {
use reverse_index::*;
let s1 = "Often, a simple if/else isn’t enough, because you have more than two possible options. Also, conditions can get quite complex. Rust has has a keyword, match, that allows you to replace complicated if/else groupings with something more powerful. It is match. Check it out:";
let s2 = "Strings are ordered lexicographically by their byte values. This orders Unicode code points based more on their positions in the code charts. This is not necessarily the same as alphabetical order, which varies by language and locale. Sorting strings according to culturally-accepted standards requires locale-specific data that is outside the scope of the str type";
let doc1 = parse(&s1);
let doc2 = parse(&s2);
let query = "simple more";
@hammett
hammett / ringbuffer.cs
Created December 31, 2015 06:49
stream ring buffer
internal class RingBufferStream : Stream
{
private const int BufferSize = 1024;
private volatile int _totalLen = 0;
private volatile int _readPosition = -1;
private volatile int _writePosition = -1;
private readonly ManualResetEventSlim _locker = new ManualResetEventSlim(false);
private readonly byte[] _buffer;
@hammett
hammett / rabbit_topic.erl
Created August 11, 2015 01:44
reminds me of MEF
%% The contents of this file are subject to the Mozilla Public License
%% Version 1.1 (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.mozilla.org/MPL/
%%
%% Software distributed under the License is distributed on an "AS IS"
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
%% the License for the specific language governing rights and
%% limitations under the License.
%%
private func validateInputs() -> Bool {
let nonEmpty = {
(data:String!) -> Bool in
return count(data) != 0
}
func inRange (min: Int!, max:Int!) -> (String!) -> Bool {
return { (data:String!) -> Bool in
let dataAsInt = data.toInt()
return (dataAsInt! >= min && dataAsInt! <= max)
data = {
orgs: [
{ key: 'orgkey', name: 'orgname',
projects: [
{ key: 'projkey', name: 'projname' }
] }
]
};
{{#data.orgs}}
@hammett
hammett / gist:11095200
Created April 19, 2014 19:41
mocha + firebase + event emitter
it("responds to 'new_user' event", function(done) {
var user = new Model.User({
'email': '[email protected]',
'name': 'testing'
});
_root.child('/users/').once('child_added', function(data) {
expect(data.name()).to.be(user._id.toString());
var userData = data.val();
expect(userData.name).to.be(user.name);
var app = require('../app');
var request = require('supertest');
describe('app', function() {
before(function(done) {
var server = app.listen(1900, done);
});
it('404 works', function() {
public ActionResult Access(Repository repos, AcceptableMedia accepts, bool isLastResourceInPath)
{
if (isLastResourceInPath && accepts.Prefers(MimeTypes.Html))
{
return new ContentNegotiatedResult();
}
return EmptyResult.Instance;
}
public class MsMvcHandler : Castle.MonoRail.Hosting.ComposableHandler
{
public override bool TryProcessRequest(HttpContextBase request)
{
var routeData = RouteTable.Routes.GetRouteData(request);
if (routeData != null)
{
var routeHandler = routeData.RouteHandler;
var requestContext = new RequestContext(request, routeData);
IHttpHandler httpHandler = routeHandler.GetHttpHandler(requestContext);