Skip to content

Instantly share code, notes, and snippets.

#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)));
}
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 "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;
}
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
#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;
@haileys
haileys / lol.rb
Created September 24, 2015 07:11
gem "activerecord", "4.2.4"
require "active_record"
ActiveRecord::Base.logger = Logger.new($stdout)
ActiveRecord::Base.establish_connection :adapter => "mysql2", :database => "test"
# ---------------------------------------------------------------------
ActiveRecord::Base.connection.transaction do
gem "rails", "3.2.21"
require "rails/all"
class MyApp < Rails::Application
end
def path_for(opts)
MyApp.routes.url_helpers.url_for(only_path: true, **opts)
rescue => e
e
func Reverse<T>(slice []T) {
for i := 0; i < len(slice) / 2; i++ {
j := len(slice) - i - 1
x := slice[j]
slice[j] = slice[i]
slice[i] = x
}
}
module GitHub
# GitHub::RenameColumn helps us rename columns on ActiveRecord models in the
# cases where we're unable or unwilling to migrate the table in question to
# rename the column.
#
# For example, to rename the column 'watcher_count' on the Repository model
# to 'stargazer_count' to better represent what data the column actually
# stores, you'd put some code like this in app/models/repository.rb:
#
# extend GitHub::RenameColumn