Skip to content

Instantly share code, notes, and snippets.

@oem
oem / gist:1303434
Created October 21, 2011 09:22
HTML5 desktop notifications - a simple example
(function ($) {
var notify, initialize, requestPermission;
notify = function () {
var notification;
if (window.webkitNotifications) {
if (window.webkitNotifications.checkPermission() > 0) {
window.webkitNotifications.requestPermission(this);
}
@oem
oem / smallest viable ember.js app
Created January 9, 2013 12:35
minimalistic example for a new ember.js app in coffeescript
# Dependencies: jquery, handlebars.js, ember.js (1.0pre)
App = Em.Application.create()
App.ApplicationView = Em.View.extend
templateName: 'application'
App.ApplicationController = Em.Controller.extend
name: "oembot"
App.Router = Em.Router.extend
VWAIT proc near
pusha
mov dx, 3DAh
v1:
in al, dx
and al, 008h
jnz v1
v2:
in al, dx
and al, 008h
@oem
oem / main.go
Created January 22, 2016 23:09
package main
import (
"fmt"
"time"
)
const timeFormat = "2006-01-02 15:04 MST"
func main() {
@oem
oem / predict_terminator_battle.rb
Created April 15, 2018 10:32
matrix multiplication to predict all labels in one go
require 'matrix'
Matrix[[10, 1000, 10], [5, 800, 2], [12, 2500, 3]] * Vector[200,-0.1,-10] # => Vector[1800.0, 900.0, 2120.0]
@oem
oem / cost_function.rb
Created April 15, 2018 11:00
cost function for linear regression
# features is a Matrix, labels and theta are Vectors
def cost_function(features, labels, theta)
m = features.row_count
predictions = predict(features, theta)
squared_errors = (predictions - labels).map { |error| error**2 }
(1.0 / (2.0 * m)) * squared_errors.reduce { |a, b| a + b }
end
def normal_equation(features, labels)
(features.transpose * features).inverse * features.transpose * labels
end
require 'minitest/autorun'
require 'matrix'
module LinearRegression
def predict(features, theta)
features * theta
end
def cost_function(features, labels, theta)
m = features.row_count
@oem
oem / prepare_data.py
Last active July 4, 2018 08:51
labelling the beer dataset for our beer-o-mat app
import turicreate as tc
import re
import os
def path_as_label(path):
label = re.search('(?<=raw/)(.+)?/.+$', path).group(1)
label = label.replace('_', ' ')
return label.title()
@oem
oem / train.py
Last active July 4, 2018 09:22
trains the beer classifier
import turicreate as tc
import os
current_dir = os.path.dirname(__file__)
data = tc.SFrame(os.path.join(current_dir, 'data/processed/beers.sframe'))
train, test = data.random_split(0.8)
model = tc.image_classifier.create(train, target='label', max_iterations=100)