This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'ffi' | |
class Time | |
module Strftime | |
extend FFI::Library | |
ffi_lib 'c' | |
attach_function :setlocale, [:int, :string], :uint | |
attach_function :strftime, [:string, :long, :string, :pointer], :long | |
setlocale(LC_ALL = 6, "de_DE") | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://www.slideshare.net/tenderlove/hidden-gems-of-ruby-19 on slide 134 | |
module FFI | |
module Library | |
TYPE_MAP = { | |
string: DL::TYPE_VOIDP, | |
pointer: DL::TYPE_VOIDP, | |
} | |
DL.constants.each{|const| | |
next unless const.to_s.match(/^TYPE_/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Mesh | |
# ... | |
def draw | |
@meshes.each.with_index{|(vao, gl_type, faces_count),mesh_index| | |
GL.glBindTexture(GL::GL_TEXTURE_2D, @tex_ids[mesh_index]) if @tex_ids[mesh_index] | |
GL.glBindVertexArray(vao) | |
GL.glDrawElements(gl_type, faces_count, GL::GL_UNSIGNED_SHORT, 0) | |
} | |
end | |
# ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=begin | |
# C dummy code | |
struct face | |
{ | |
unsigned int mNumIndices; | |
unsigned int* mIndices; | |
} | |
struct mesh | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'ffi' | |
# simple GeoLiteCity IP lookup | |
# | |
# install: | |
# * archlinux => pacman -S geoip | |
# * database at http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz | |
# | |
module GeoIP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
cd "$(dirname $(readlink -f $0))" | |
python2 pronterface.py -c config/slic3r $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# install on archlinux: | |
# % pacman -S cpanminus | |
# % cd /path/to/Slic3r-git | |
# % HOME="`pwd`/vendor" cpanm -n --local-lib="`pwd`/vendor" Boost::Geometry::Utils Math::Clipper Math::ConvexHull Math::ConvexHull::MonotoneChain Math::Geometry::Voronoi Math::PlanePath Moo Wx | |
cd "$(dirname $(readlink -f $0))" | |
PERL5LIB="vendor/lib/perl5:vendor/lib/perl5/x86_64-linux-thread-multi" ./slic3r.pl $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'bundler/setup' | |
require 'reel' | |
require 'rack' | |
class RequestActor | |
include Celluloid | |
def initialize(app, connection); @app, @connection = app, connection; end | |
def run | |
env = @connection.request.headers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Hash | |
alias get [] | |
def [](*a) | |
a.size == 1 ? get(*a) : (self[a.shift][*a] rescue nil) | |
end | |
end | |
p( {}[:a, :b] ) | |
p( {:a => {:b => "c"}}[:a, :b] ) | |
p( {:a => {:b => "c"}}[:a, :b, :c] ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'ffi' | |
class FFI::Struct | |
def method_missing(m=nil, *a) | |
m ? self[m] : super(m, *a) | |
end | |
def self.array(size) | |
klass = self | |
Class.new(FFI::Struct){ layout :array, [klass, size]; def [](idx); super(:array)[idx]; end; }.new | |
end |