Skip to content

Instantly share code, notes, and snippets.

View mfpiccolo's full-sized avatar

Mike Piccolo mfpiccolo

View GitHub Profile
require ‘ffi’
module Scrape
extend FFI::Library
ffi_lib ‘./debug/libscrape.dylib’
attach_function :sum, [:int32, :int32], :int32
end
puts Scrape.sum(2, 3) == 5 ? “Gone Dun It!” : “Uhhhh????”
source ‘https://rubygems.org'
gem ‘ffi’
@mfpiccolo
mfpiccolo / a-rubyist-rusting-part-1-3.rs
Created July 5, 2015 19:25
External Rust Function
#[no_mangle]
pub extern fn sum(x: i32, y: i32) -> i32 {
x + y
}
[package]
name = "scrape"
version = "0.1.0"
authors = ["Mike Piccolo <[email protected]>"]
[lib]
name = "embed"
crate-type = ["dylib"]
@mfpiccolo
mfpiccolo / a-rubyist-rusting-part-1-1.rs
Last active August 29, 2015 14:24
Initial sum function
fn sum(x: i32, y: i32) -> i32 {
x + y
}
#[test]
fn it_works() {
assert!(sum(1, 2) == 3);
}
#minitest/spec
# Drop SOLO in the name of the test you want to run and then run
# solo and tab complete the path/to/the/test/file.rb
solo() {
ruby -Itest $1 --name /SOLO/
}
# describe SomeClass do
# it "does some stuff SOLO" do
guard "minitest", all_on_start: false, start_on_start: false do
# with Minitest::Spec
watch(%r|^test/(.*)_test\.rb$|)
watch(%r|^app/(.*)/(.*)\.rb$|) { |m| "test/#{m[1]}/#{m[2]}_test.rb" }
watch(%r|^lib/(.*)([^/]+)\.rb$|) { |m| "test/#{m[1]}#{m[2]}_test.rb" }
watch(%r|^test/test_helper\.rb$|) { "test" }
watch(%r|^test/support/|) { "test" }
end
import Ember from 'ember';
var Pollable = Ember.Mixin.create({
afterModel: function (model, transition) {
var self = this;
this._super(model, transition);
var interval_info = this.get('interval_info');
if (!interval_info) {
interval_info = Ember.Object.create({
@mfpiccolo
mfpiccolo / money-rails-four-decimal.rb
Created March 31, 2015 22:30
Money Rails with 4 decimal places
MoneyRails.configure do |config|
config.register_currency = {
:priority => 1,
:iso_code => "USD1",
:name => "USD with subunit of 4 digits",
:symbol => "$",
:symbol_first => true,
:subunit => "Subcent",
:subunit_to_unit => 10000,
:thousands_separator => ",",
@mfpiccolo
mfpiccolo / serializer_monkey.rb
Last active August 29, 2015 14:13
A active record monkey patch to make serialization easy with active model serializers
# Monkey patch for ActiveRecord::Base to return serialized JSON in the format
# of an ActiveModel::Serializer.
module SerializedJson
extend ActiveSupport::Concern
def to_serial(serializer=nil, opts={})
if self.respond_to?(:map)
serializer ||= (self.base_class.name + "Serializer").constantize
serialized_collection = self.map do |resource|