Skip to content

Instantly share code, notes, and snippets.

@lloeki
lloeki / nokogiri_builders.rb
Created September 27, 2013 08:34
Using Nokogiri::XML::Builder in lieu of stock pure ruby Builder for Rails builder templates
# config/initializers/nokogiri_builders.rb
# Using Nokogiri::XML::Builder in lieu of stock pure ruby Builder for Rails builder templates
# unrelated, but you might want this too to enable parsing
# XML params with Nokogiri
#ActiveSupport::XmlMini.backend = 'Nokogiri'
module Nokogiri
module XML
class Builder
@lloeki
lloeki / Settings
Last active February 15, 2016 21:04
PS3 controller setting for Fez on OSX
~/Library/Application Support/FEZ/Settings
--8<-- Default (Xbox 360)
gamepadMapping Jump=1 GrabThrow=0 CancelTalk=2 OpenMap=8 OpenInventory=3 MapZoomIn=5 MapZoomOut=4 Pause=9 RotateLeft=6 RotateRight=7 FpViewToggle=10 ClampLook=11
--8<-- Sony PS3 DualShock3 / Logitech RumblePad 2
gamepadMapping Jump=14 GrabThrow=15 CancelTalk=13 OpenMap=0 OpenInventory=12 MapZoomIn=9 MapZoomOut=8 Pause=3 RotateLeft=10 RotateRight=11 FpViewToggle=1 ClampLook=2
--8<--
@lloeki
lloeki / patch_ati6870_gibba.sh
Created April 10, 2014 12:36
Fix 5-ports for ATI 6870 on OSX (10.8/10.9) using Gibba framebuffer
cd /System/Library/Extensions/ATI6000Controller.kext/Contents/MacOS
sudo perl -pi -e 's|\x00\x04\x00\x00\x04\x03\x00\x00\x00\x01\x00\x00\x12\x04\x05\x01\x00\x04\x00\x00\x04\x03\x00\x00\x00\x01\x00\x00\x22\x05\x04\x02\x00\x08\x00\x00\x04\x02\x00\x00\x00\x01\x00\x00\x11\x02\x06\x04\x00\x02\x00\x00\x14\x02\x00\x00\x00\x01\x00\x00\x00\x00\x03\x05\x04\x00\x00\x00\x04\x02\x00\x00\x00\x01\x00\x00\x11\x02\x01\x03|\x00\x04\x00\x00\x04\x03\x00\x00\x00\x01\x00\x00\x12\x04\x04\x01\x00\x04\x00\x00\x04\x03\x00\x00\x00\x01\x00\x00\x22\x05\x05\x02\x00\x08\x00\x00\x04\x02\x00\x00\x00\x01\x00\x00\x11\x02\x06\x04\x00\x02\x00\x00\x14\x02\x00\x00\x00\x01\x00\x00\x00\x00\x03\x05\x04\x00\x00\x00\x04\x02\x00\x00\x00\x01\x00\x00\x11\x02\x01\x06|g' AMD6000Controller

Keybase proof

I hereby claim:

  • I am lloeki on github.
  • I am lloeki (https://keybase.io/lloeki) on keybase.
  • I have a public key whose fingerprint is D2CB 6310 2C72 5899 1C0D 4A53 971B 4D9F 125C D31E

To claim this, I am signing this object:

@lloeki
lloeki / arel_composition_without_activerecord.rb
Last active August 15, 2023 18:11
Arel composition (without ActiveRecord)
# rebuttal of http://www.try-alf.org/blog/2013-10-21-relations-as-first-class-citizen
require 'arel'
require 'sqlite3'
require 'pry'
def suppliers
@suppliers ||= Arel::Table.new(:suppliers)
end
@lloeki
lloeki / lua.go
Created August 7, 2014 07:16
Go <-> Lua
package main
/*
#cgo LDFLAGS: -lluajit-5.1
#include <stdlib.h>
#include <stdio.h>
#include <luajit-2.0/lua.h>
#include <luajit-2.0/lualib.h>
#include <luajit-2.0/lauxlib.h>
@lloeki
lloeki / monad_id.rb
Created September 1, 2014 11:52
Identity monad in Ruby
# http://moonbase.rydia.net/mental/writings/programming/monads-in-ruby/01identity
# Identity monad
class Identity
def initialize(value)
@value = value
end
# unit operation: Haskell 'return'
def self.munit(value)
@lloeki
lloeki / class_diagram.rake
Last active August 29, 2015 14:10
Rails class diagram (e.g models) with graphviz
# (c) Loic Nageleisen
# License: MIT
Node = Struct.new(:type, :name, :attributes)
Edge = Struct.new(:type, :from, :to, :name)
class DiagramGraph
def initialize
@nodes = []
@edges = []
@lloeki
lloeki / brutalize_openssl.rb
Created December 2, 2014 10:29
Violently disable OpenSSL cert validation (dangerous!)
require 'openssl'
class OpenSSL::SSL::SSLContext
def verify_mode
OpenSSL::SSL::VERIFY_NONE
end
def verify_mode=(_)
@verify_mode = OpenSSL::SSL::VERIFY_NONE
end
@lloeki
lloeki / gist:62239da19ec25f90f215
Created December 16, 2014 16:15
open-vm-tools with clipboard and drag and drop on Ubuntu 14.04 Trusty Tahr
# You should be using open-vm-tools instead of vmware tools, because package manager.
# Also I hate third parties that write out of /opt and /usr/local.
# open-vm-tools-desktop is badly packaged though, here are the missing links:
sudo apt-get install open-vm-tools open-vm-tools-desktop
# Reboot, and resize works, but no DnD nor clipboard
sudo mkdir /var/run/vmblock-fuse
sudo su -l -c "vmware-vmblock-fuse -o subtype=vmware-vmblock,default_permissions,allow_other /var/run/vmblock-fuse"
# Now we have /run/vmblock-fuse populated.
# Adding an upstart rule in /etc/init is left as an exercise to the reader.