Skip to content

Instantly share code, notes, and snippets.

@pehrlich
pehrlich / CertificateNSS.cpp
Created July 17, 2015 20:20
Cross Platform Mozilla NSS Root Certificate Installation
#include "stdafx.h"
#include "CertificateNSS.h"
#include "Certificate.h"
#include <boost/filesystem/operations.hpp>
#include <nss.h>
#include <cert.h>
#include <certdb.h>
ProfileLocker::ProfileLocker(const boost::filesystem::path& profilePath) : m_isValid(false)

Leap Motion + VR in Javascript

Awesome! You’re doing a hackathon. This is a quickstart guide for getting going.

Here are the components you need, after THREE.js and Leap.js:

  • OculusRiftEffect - Renders the lense effect with THREE.js or Mozilla’s native API*.
  • OculusControls.js - Takes position tracking data from your oculus to your web app
  • The LeapJS optimizeHMD flag.
  • leap.transform.js - Re-orients the hand for usage in top-down mode.
def expression_backtrace(backtrace)
new_trace = []
backtrace.each do |line|
match = /(.*):([0-9]+):in/.match line
file, linenum = match[1], match[2].to_i
new_trace << line
if File.exist?(file)
expr = File.readlines(file)[linenum - 1]
@pehrlich
pehrlich / boolean.rb
Created February 15, 2013 21:25
Rails Boolean to string yes no
class TrueClass
def to_s(style = :boolean)
case style
when :word then 'yes'
when :Word then 'Yes'
when :number then '1'
else 'true'
end
end
end
@pehrlich
pehrlich / full_error_messages.rb
Created February 4, 2013 23:51
Print out full error messages for nested models
module FullErrorMessages
extend ActiveSupport::Concern
# includes errors on this model as well as any nested models
def all_error_messages
messages = self.errors.messages.dup
messages.each do |column, errors|
if self.respond_to?(:"#{column}_attributes=") && (resource = self.send(column))
messages[column] = resource.errors.messages
end
@pehrlich
pehrlich / support_controller.rb
Created October 25, 2012 01:52
Ruby code to turn Twilio text messages in to zendesk tickets
# this uses the official zendesk rubygem: https://github.com/zendesk/zendesk_api_client_rb
class SupportController < ApplicationController
skip_before_filter :verify_authenticity_token
def twilio_inbound
raise "Invalid Twilio Account Id" unless params[:AccountSid] == $twilio_account_id
raise "Invalid :from number" unless from_number = params[:From]
raise "Invalid message :body" unless body = params[:Body]
@pehrlich
pehrlich / brawl.md
Created October 24, 2012 04:58
Helicopter Event

Equipment

  • helicopters (todo, calculate charge time, flgiht time, find helicopters per person)
  • remote controls (todo: know why they bug out, how to repair)
  • AirZookas (make our own?)
  • spare helicpter parts (blades, gyros)

Charge time: 56 minutes 59 minutes

@pehrlich
pehrlich / test.mirah
Created October 16, 2012 01:59
verbose mirah copmlication of bike.mirag (LeJos)
~/Projects/LeJos/bike mirahc --verbose --java --classpath /Users/peter/Downloads/leJOS_NXJ_0.9.1beta-3/lib/nxt/classes.jar test.mirah
Parsing...
test.mirah
Inferring types...
* [AST] [Import] Import(* = lejos.nxt.*) resolved!
* [AST] [Import] Import(GyroSensor = lejos.nxt.addon.GyroSensor) resolved!
* [AST] [Import] Import(GyroDirectionFinder = lejos.nxt.addon.GyroDirectionFinder) resolved!
* [Mirah::Typer] New type defined: 'MyButtonListener' < ''
* [AST] [Implements] Implements resolved!
* [Mirah::Typer] Learned local type under #<Mirah::AST::StaticScope:0x171ccb0> : b = Type(lejos.nxt.Button)
@pehrlich
pehrlich / site_controller.rb
Created September 11, 2012 23:15
Implementing Google's hashbang/Ajax crawl with Jruby on Rails
class SiteController < ApplicationController
def index
# who the f*!@ knows how to make a rails route for a get parameter?
if frag = params[:'_escaped_fragment_']
# good read: (Akephalos)
# http://robots.thoughtbot.com/post/1658763359/thoughtbot-and-the-holy-grail
# http://robots.thoughtbot.com/post/4583605733/capybara-webkit
# todo: phantomjs (webkit based)
.block-centered {
margin-left: auto;
margin-right: auto;
}
.center, .centered {
text-align: center;
}