Skip to content

Instantly share code, notes, and snippets.

@pehrlich
pehrlich / CertificateNSS.cpp
Created Jul 17, 2015
Cross Platform Mozilla NSS Root Certificate Installation
View CertificateNSS.cpp
#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)
View leapmotion-vr-quickstart.md

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.
View gist:5000157
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 Feb 15, 2013
Rails Boolean to string yes no
View boolean.rb
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 Feb 4, 2013
Print out full error messages for nested models
View full_error_messages.rb
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 Oct 25, 2012
Ruby code to turn Twilio text messages in to zendesk tickets
View support_controller.rb
# 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 Oct 24, 2012
Helicopter Event
View brawl.md

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 Oct 16, 2012
verbose mirah copmlication of bike.mirag (LeJos)
View test.mirah
~/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 Sep 11, 2012
Implementing Google's hashbang/Ajax crawl with Jruby on Rails
View site_controller.rb
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)
View helpers.scss
.block-centered {
margin-left: auto;
margin-right: auto;
}
.center, .centered {
text-align: center;
}