Skip to content

Instantly share code, notes, and snippets.

View nathanjsharpe's full-sized avatar

Nathan Sharpe nathanjsharpe

View GitHub Profile
@nathanjsharpe
nathanjsharpe / AssetStore.js
Created October 29, 2015 19:22
Merge and sync
// assets param is either a plain js object or an array of plain js objects
_merge(assets) {
// If parameter is a single object, make it an array
assets = Array.isArray(assets) ? assets : [assets];
// From object(s), create an ordered map of id => record
let newAssets = new OrderedMap(assets.map(asset => [asset.id, new Asset(asset)]));
// Merge in new assets, keeping old if new is equal (same values) to preserve reference equality
this._assets = this._assets.mergeWith((prev, next) => prev.equals(next) ? prev : next, newAssets);
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Trak-It Web App</title>
<script src="//maps.google.com/maps/api/js?v=3&sensor=false"></script>
<link rel="stylesheet" href="static/styles.css">
</head>
<body id="modal-tag">
<div id="app" class="content">
app.factory('appSettings', function() {
var profile = "default";
var configSelections = {
"DataRate": "500SPS",
"TestAmp": "1x(VREFP-VREFN)/2.4mV",
"TestFreq": "fclk/2^21",
"PDRefBuf": 1,
"EnableLOFF": "LOFF Disabled",
"COMP_TH": "95%",
"ILEAD_OFF": "6nA",
@nathanjsharpe
nathanjsharpe / image.rb
Last active August 29, 2015 14:07
i18n + associations?
class Image < ActiveRecord::Base
belongs_to :snippet
end
local all postgres trust
local all nathan peer
local all all md5
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 md5
@nathanjsharpe
nathanjsharpe / place_serializer.rb
Created September 17, 2013 20:51
rather than specify the association using has_one or belongs_to, you can define it yourself
class PlaceSerializer < ActiveModel::Serializer
attributes :id, :foo, :bar, :features
def features
feature
end
end
<h1>Editing {{.Title}}</h1>
<form action="/save/{{.Title}}" method="POST">
<div>
<textarea name="body" cols="80" rows="20">{{printf "%s" .Body}}</textarea>
</div>
<div>
<input type="submit" value="Save">
</div>
</form>
@nathanjsharpe
nathanjsharpe / example.rb
Created November 17, 2012 21:55
Has many through example
class ServiceElement < ActiveRecord::Base
attr_accessible :body, :title, :category, :source, :number, :file
has_many :parts
has_many :presentations, through: :parts, order: "presentations.date"
end
class Part < ActiveRecord::Base
attr_accessible :position, :presentation_id, :service_element_id
@nathanjsharpe
nathanjsharpe / signup_spec.rb
Created November 14, 2012 22:36
Rspec problem
describe 'on signup page' do
before { visit '/signup' }
let(:submit) { "Create Account" }
context "with invalid information" do
# tests here work great
end
@nathanjsharpe
nathanjsharpe / reset_sequence.sql
Created October 15, 2012 16:02
Postgres Reset Sequence Function
CREATE OR REPLACE FUNCTION reset_sequence(tablename text) RETURNS "pg_catalog"."void" AS $$
DECLARE
BEGIN
RAISE NOTICE 'Resetting sequence for %...', tablename;
EXECUTE 'SELECT setval(''' || tablename || '_id_seq'', (SELECT MAX(id) FROM ' || tablename || '))';
RAISE NOTICE 'Sequence reset.';
END;