Skip to content

Instantly share code, notes, and snippets.

View ianterrell's full-sized avatar

Ian Terrell ianterrell

  • University of Virginia
  • Charlottesville, VA
View GitHub Profile
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>MathJax example</title>
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script id="MathJax-script" async
src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js">
</script>
require 'securerandom'
require 'base64'
require 'uri'
# This is probably provided by a library in your language.
def encrypt(data)
salt = ""
8.times { salt << rand(255).chr }
cipher = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
cipher.encrypt
@ianterrell
ianterrell / rgb_led.particle.c
Last active January 15, 2017 02:01
RGB LED Particle Photon Basic Firmware
// From http://diotlabs.daraghbyrne.me/2-leds-continued/using-rgb-leds/
int redPin = D0; // RED pin of the LED to PWM pin **A4**
int greenPin = D2; // GREEN pin of the LED to PWM pin **D0**
int bluePin = D3; // BLUE pin of the LED to PWM pin **D1**
int redValue = 255; // Full brightness for an Cathode RGB LED is 0, and off 255
int greenValue = 255; // Full brightness for an Cathode RGB LED is 0, and off 255
int blueValue = 255; // Full brightness for an Cathode RGB LED is 0, and off 255</td>
void setup()
@ianterrell
ianterrell / GenerateEquatable.swift
Last active October 13, 2016 18:36 — forked from Ben-G/GenerateEquatable.swift
Generate Equatable in terms of member fields
//: Playground - noun: a place where people can play
import UIKit
func generateEquatable(_ t: Any) -> String {
var output = ""
let mirrorPlace = Mirror(reflecting: t)
let type = mirrorPlace.subjectType
output += ("extension \(type): Equatable {\n")
// This handles most storyboard style injection needs
extension UIViewController {
func injectable<T>() -> T? {
var controller: UIViewController? = self
if let nav = self as? UINavigationController {
controller = nav.viewControllers.first
}
return controller as? T
}
function execute_loop() {
var vmfunc, pathtab, path;
var pathstart, pathend;
if (resumefuncop) {
//qlog("### at resume time, storing value " + resumevalue + " at funcop " + resumefuncop.key);
store_operand_by_funcop(resumefuncop, resumevalue);
resumefuncop = null;
resumevalue = 0;
}
@ianterrell
ianterrell / BDD.swift
Last active August 29, 2015 14:02
Rspec style matchers for Swift
import XCTest
protocol Matchable : Equatable, Comparable { }
class Matcher<T : Matchable> {
let subjectWrapper: T[]
var subject: T {
get {
return subjectWrapper[0]
#define p1prime(p1,p2,p3,p4) (u0*u0*u0*p1 + (t0*u0*u0 + u0*t0*u0 + u0*u0*t0)*p2 + (t0*t0*u0 + u0*t0*t0 + t0*u0*t0)*p3 + t0*t0*t0*p4)
#define p2prime(p1,p2,p3,p4) (u0*u0*u1*p1 + (t0*u0*u1 + u0*t0*u1 + u0*u0*t1)*p2 + (t0*t0*u1 + u0*t0*t1 + t0*u0*t1)*p3 + t0*t0*t1*p4)
#define p3prime(p1,p2,p3,p4) (u0*u1*u1*p1 + (t0*u1*u1 + u0*t1*u1 + u0*u1*t1)*p2 + (t0*t1*u1 + u0*t1*t1 + t0*u1*t1)*p3 + t0*t1*t1*p4)
#define p4prime(p1,p2,p3,p4) (u1*u1*u1*p1 + (t1*u1*u1 + u1*t1*u1 + u1*u1*t1)*p2 + (t1*t1*u1 + u1*t1*t1 + t1*u1*t1)*p3 + t1*t1*t1*p4)
class NSString < Mobi::Cocoa::Object
end
class UIAlertView < Mobi::Cocoa::Object
def self.alert(title, message, options={})
alert = UIAlertView._alloc \
._initWithTitle _S(title),
:message, _S(message),
:delegate, nil,
:cancelButtonTitle, options[:cancel_title] ? _S(options[:cancel_title]) || nil,
@ianterrell
ianterrell / gist:1102751
Created July 24, 2011 15:49 — forked from deathbob/gist:1102683
Meta module madness
module Foo
def bar
@bar ||= self.snakes
end
end
class Baz
def self.snakes
[:cobra]