Skip to content

Instantly share code, notes, and snippets.

View mattgreen's full-sized avatar

Matt Green mattgreen

View GitHub Profile
@ishikawa
ishikawa / llvm.global_ctor.rb
Created January 4, 2011 16:57
Creates a "llvm.global_ctor" intrinsic global variable by using ruby-llvm
# Creates a "llvm.global_ctor" intrinsic global variable by using ruby-llvm
#
# ; ModuleID = 'global_ctors_sample'
#
# %0 = type { i32, void ()* }
#
# @llvm.global_ctors = appending global [1 x %0] [%0 { i32 65535, void ()* @__ctor }]
#
# define void @__ctor() {
# ret void
@hypomodern
hypomodern / synchrony_multi_example.rb
Created May 13, 2011 15:17
How do I use EM::Synchrony::Multi inside a controller action?
# So, I have an controller action that makes multiple calls to third-party APIs over http.
# I'd like to parallelize these calls via EventMachine::Synchrony::Multi, but can't figure out how to wire the controller
#
# This works fine from, say, a script on the command line, but not in a controller running on a thin server.
#
# What I was missing: a) rack/fiber_pool, b) we don't need the EM.synchrony block
class DemoController < ApplicationController # or a sinatra app, same result
# ...
def evented
multi = nil
@kyledrake
kyledrake / gist:1498932
Last active August 2, 2016 04:31
Neocities' Rainbows! config file - https://neocities.org
# This is Neocities' Rainbows! config file. We are using this in production to run all our web apps.
# It works really well for us and has been heavily load tested, so I wanted to share it with the community.
#
# In my opinion, this is the best way to deploy a ruby web application. Unlike EventMachine based solutions,
# it uses real ruby threads, which allows it to take advantage of the internal non-blocking IO pattern
# in MRI.
#
# Contrary to popular belief, MRI doesn't block execution to wait on IO when you are using threads, even
# with the GIL. The requests are done concurrently for anything that is based on the IO class. This
# includes things like Net::HTTP and even `system commands`. Grep the MRI Ruby source code for
// as NSObject
RKObjectMapping* mapping = [RKObjectMapping mappingForClass:[TestMappable class]];
[mapping mapKeyPath:@"numbers" toAttribute:@"orderedSet"];
TestMappable* object = [[[TestMappable alloc] init] autorelease];
id<RKParser> parser = [[RKParserRegistry sharedRegistry] parserForMIMEType:@"application/json"];
id data = [parser objectFromString:@"{\"numbers\":[1, 2, 3]}" error:nil];
RKObjectMappingOperation* operation = [[RKObjectMappingOperation alloc] initWithSourceObject:data destinationObject:object mapping:mapping];
BOOL success = [operation performMapping:nil];
@sw17ch
sw17ch / indented_parsec_example.lhs
Created March 16, 2012 04:31
A full example demonstrating the use of the indentation parser provided by the 'indents' package: http://hackage.haskell.org/package/indents
> module Main where
First, import all the needed modules.
> import Text.Parsec hiding (State)
> import Text.Parsec.Indent
> import Control.Monad.State
Next, define our new Parser type. This replaces the Identity monad
with the (State SourcePos) monad.
@bokmann
bokmann / ActiveRepository.rb
Created March 27, 2012 16:15
ActiveRepository Strawman
# MOTIVATION: As rails apps are growing, people are noticing the drawbacks
# of the ActiveRecord pattern. Several apps I have seen, and several
# developers I have spoken to are looking towards other patterns for object
# persistence. The major drawback with ActiveRecord is that the notion
# of the domain object is conflated with what it means to store/retrieve
# it in any given format (like sql, json, key/value, etc).
#
# This is an attempt to codify the Repository pattern in a way that would
# feel comfortable to beginner and seasoned Ruby developers alike.
#
@ijp
ijp / SECD2.hs
Created February 18, 2013 22:21
-- An implementation of Peter Landin's SECD machine, as described in
-- "The Mechanical Evaluate of Expressions"
import Prelude hiding (lookup)
type Name = String
data Expr a = ID Name
| Obj a
| Fun Name (Expr a)
| Apply (Expr a) (Expr a)
@mislav
mislav / _readme.md
Last active September 28, 2024 23:03
tmux-vim integration to transparently switch between tmux panes and vim split windows

I use tmux splits (panes). Inside one of these panes there's a Vim process, and it has its own splits (windows).

In Vim I have key bindings C-h/j/k/l set to switch windows in the given direction. (Vim default mappings for windows switching are the same, but prefixed with C-W.) I'd like to use the same keystrokes for switching tmux panes.

An extra goal that I've solved with a dirty hack is to toggle between last active panes with C-\.

Here's how it should work:

@istepanov
istepanov / lcs.py
Created September 10, 2013 08:23
Search longest common substrings using generalized suffix trees built with Ukkonen's algorithm, written in Python 2.7
#!/usr/bin/env python
# -*- coding: utf-8
"""
Search longest common substrings using generalized suffix trees built with Ukkonen's algorithm
Author: Ilya Stepanov <code at ilyastepanov.com>
(c) 2013
"""
@neel-krishnaswami
neel-krishnaswami / re.ml
Created November 7, 2013 12:20
Implementation of DFA-based regexp matching using Antimirov derviatives
type re = C of char | Nil | Seq of re * re | Bot | Alt of re * re | Star of re
let rec null = function
| C _ | Bot -> false
| Nil | Star _ -> true
| Alt(r1, r2) -> null r1 || null r2
| Seq(r1, r2) -> null r1 && null r2
module R = Set.Make(struct type t = re let compare = compare end)
let rmap f rs = R.fold (fun r -> R.add (f r)) rs R.empty