Skip to content

Instantly share code, notes, and snippets.

View haileys's full-sized avatar

Hailey Somerville haileys

View GitHub Profile
require "./tinyparse"
json = Tinyparse.build do
token = ->str { [str, /\s*/] }
tok_open_brace *token["{"]
tok_close_brace *token["}"]
tok_open_bracket *token["["]
tok_close_bracket *token["]"]
tok_colon *token[":"]

References in Ruby

Just for fun, I decided to add references to Ruby.

I decided to use Perl's backslash syntax, so for example you'd write \foo to take a reference to the local variable foo. You can also take a reference to instance variables, class variables and globals.

I have attached a patch in this gist if you're interested in the implementation or you want to try it out on your own copy of Ruby.

This was just a fun little exercise for me - I don't expect that this would ever be merged in to Ruby itself.

#include <iostream>
using namespace std;
class HelloCppTest {
public:
static void testMain() {
cout << "Hello, C++er!" << endl;
}
};
#include <mruby.h>
#include <mruby/compile.h>
#include <mruby/string.h>
#include <stdio.h>
mrb_state* mrb;
void p(mrb_value value) {
printf("--> %s\n", mrb_str_to_cstr(mrb, mrb_inspect(mrb, value)));
}
require "nokogiri"
require "pry"
doc = Nokogiri::XML(File.read("collection.nml"))
def update_playlist(doc, playlist_name, xpath)
playlist = doc.xpath("/NML/PLAYLISTS//NODE[@TYPE='PLAYLIST'][@NAME='#{playlist_name}']/PLAYLIST").first
playlist.children.remove
require "nokogiri"
require "pry"
doc = Nokogiri::XML(File.read("collection.nml"))
def update_playlist(doc, playlist_name, xpath)
playlist = doc.xpath("/NML/PLAYLISTS//NODE[@TYPE='PLAYLIST'][@NAME='#{playlist_name}']/PLAYLIST").first
playlist.children.remove
@haileys
haileys / query.js
Last active November 21, 2017 06:41
function query<T>(selector: string, klass: Class<T>): T {
let element = document.querySelector(selector);
if (!(element instanceof klass)) {
throw new TypeError("expected " + selector + " to select element of type " + (klass : Function).name);
}
return element;
}
import Control.Monad
import Data.Monoid
data MState s a = MState s a
instance Monoid s => Functor (MState s) where
fmap f (MState st x) = MState st (f x)
instance Monoid s => Applicative (MState s) where
pure = return
require "set"
module GitHub
module AttrIgnore
attr_reader :ignored_columns
def attr_ignore(*columns)
@ignored_columns ||= Set.new
@ignored_columns |= columns.map(&:to_s)
end
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <errno.h>
struct worker_ctx {
pthread_t thr;
size_t n;
size_t stride;
size_t offset;