Skip to content

Instantly share code, notes, and snippets.

View dvliman's full-sized avatar

David Liman dvliman

View GitHub Profile
@dvliman
dvliman / gist:1379940
Created November 20, 2011 07:45
calendar in terminal
cal | sed "s/.*/ & /;s/ $(date +%e) / [] /"
@dvliman
dvliman / bpnn.py
Created November 21, 2011 08:25
neural network python
# Back-Propagation Neural Networks
#
# Written in Python. See http://www.python.org/
# Placed in the public domain.
# Neil Schemenauer <nas@arctrix.com>
import math
import random
import string
@dvliman
dvliman / bpnn.rb
Created November 21, 2011 08:26
neural network ruby
# Back-Propagation Neural Networks
# Written in Ruby with NArray. See http://narray.rubyforge.org/
#
# This program is a translation of bpnn.py written by Neil Schemenauer <nas@arctrix.com>
# The original source is available at http://python.ca/nas/
require "narray"
# calculate a random number where: a <= rand < b
class NArray
@dvliman
dvliman / google-contacts-authsub.html
Created December 28, 2011 08:37 — forked from boazsender/google-contacts-authsub.html
Boilerplate for authsubbing a user to grant permissions to their contacts, and loading in an arbitrary number of their contacts into the page.
<!DOCTYPE html>
<html lang="en">
<head>
<script src="http://code.jquery.com/jquery.js"></script>
<script src="http://google.com/jsapi"></script>
<script src="google-contacts-authsub.js"></script>
</head>
<body>
<!-- Google requires an image to be on the page -->
<img src="https://localhost/img/1px.png">
@dvliman
dvliman / rspec-syntax-cheat-sheet.rb
Created January 25, 2012 21:01 — forked from dnagir/rspec-syntax-cheat-sheet.rb
RSpec 2 syntax cheat sheet by example
# RSpec 2.0 syntax Cheet Sheet by http://ApproachE.com
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below)
module Player
describe MovieList, "with optional description" do
it "is pending example, so that you can write ones quickly"
it "is already working example that we want to suspend from failing temporarily" do
pending("working on another feature that temporarily breaks this one")
package com.dvliman.tenten.model;
import java.util.List;
public class Base {
public enum Status {
ACTIVE,
INACTIVE,
DELETED,
@dvliman
dvliman / api.rb
Created June 22, 2012 21:41 — forked from lucatironi/api.rb
Snippets for an API with grape
# Server App
# This file must be in lib/myapp/api.rb
module MyApp
module Entities
class Products < Grape::Entity
expose :id, :code, :name, :short_description
expose :description, :unless => { :collection => true }
expose (:category) { |model, options| model.category.name }
expose (:brand) { |model, options| model.brand.name }
end
execute typical instruction 1 nanosec 1/1,000,000,000 sec
fetch from L1 cache memory 0.5 nanosec
branch misprediction 5 nanosec
fetch from L2 cache memory 7 nanosec
Mutex lock/unlock 25 nanosec
fetch from main memory 100 nanosec
send 2K bytes over 1Gbps network 20,000 nanosec
read 1MB sequentially from memory 250,000 nanosec
fetch from new disk location (seek) 8,000,000 nanosec
read 1MB sequentially from disk 20,000,000 nanosec
@dvliman
dvliman / gist:3209234
Created July 30, 2012 19:09
def require_all
def require_all(path)
glob = File.join(File.dirname(__FILE__), path, '*.rb')
Dir[glob].each do |f|
require f
end
end
@dvliman
dvliman / sudoku_solver.cpp
Created August 14, 2012 02:31 — forked from keveman/sudoku_solver.cpp
Sudoku solver in C++11
#include <iterator>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <iostream>
#include <cassert>
#include <memory>
#include <thread>
#include <future>