Skip to content

Instantly share code, notes, and snippets.

@jarcoal
jarcoal / GoAssertEqErr.sublime-snippet
Last active October 23, 2022 02:13
Golang Sublime Snippets
<snippet>
<content><![CDATA[
assert.Equal(t, ${1:err}, nil)
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>aerr</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.go</scope>
</snippet>
@jarcoal
jarcoal / mock.go
Created February 11, 2014 18:29
http mock for golang
package httpmock
import (
"errors"
"net/http"
)
// Responders are callbacks that receive and http request and return a mocked response.
type Responder func(*http.Request) (*http.Response, error)
@jarcoal
jarcoal / keybase.md
Created December 1, 2017 05:08
keybase.md

Keybase proof

I hereby claim:

  • I am jarcoal on github.
  • I am jarcoal (https://keybase.io/jarcoal) on keybase.
  • I have a public key ASDQA1LOJi9YwraJWlNuIQDFaqu-SI6eOSm_w9K9t9zlPwo

To claim this, I am signing this object:

@jarcoal
jarcoal / location2d.lua
Created May 14, 2013 06:02
Misc Lua Scripts for Redis
local radius, x, y = unpack(ARGV)
local locations = redis.call('HGETALL', KEYS[1])
local nearby = {}
for i = 1, #locations, 2 do
local cid, cloc = locations[i], locations[i+1]
local cx, cy = string.sub(cloc, 1, 2), string.sub(cloc, 3, 4)
if (cx - x)^2 + (cy - y)^2 <= radius^2 then
table.insert(nearby, cid)
@jarcoal
jarcoal / destroy.js
Created November 18, 2016 19:31
Technique to remove a record from a restmod collection without waiting for a server response
// Create mixin to extend Records with a custom destroy method
app.factory('restmodDestroyMixin', function(restmod) {
return restmod.mixin({
$extend: {
Record: {
$destroyImmediately: function() {
this.$scope.$remove(this);
return this.$destroy();
},
}
@jarcoal
jarcoal / moment-angular.js
Created August 5, 2013 05:40
MomentJS adapter for AngularJS
angular.module('moment', []).factory('moment', ['$window', function($window){
return $window.moment;
}]).filter('moment', ['moment', function(moment) {
return function(dateString, format) {
return moment(dateString).format(format);
};
}]);
@jarcoal
jarcoal / modal.less
Created October 22, 2012 21:43
Static Modal
body.modal-open {
overflow: hidden;
}
.modal-backdrop {
.hide;
background-color: rgba(255, 255, 255, 0.8);
.opacity(100);
overflow-x: auto;
@jarcoal
jarcoal / heroku-config.txt
Created October 17, 2012 22:29
Versioning Static Assets w/ Heroku Config Vars
heroku config:add JS_VERSION=1 CSS_VERSION=1 --app=YOUR_APPLICATION_NAME
@jarcoal
jarcoal / bad-template-loop.html
Created October 9, 2012 01:05
prefetch related post
<ul>
{% for product in products %}
<li>
<h4>{{ product.name }}</h4>
<ul>
{% for feature in product.feature_set.all %}
<li>{{ feature.name }}</li>
{% endfor %}
</ul>
@jarcoal
jarcoal / settings.py
Created September 9, 2012 00:05
Simple Extension to Django's default ModelBackend to force it to select a profile in addition to the user.
AUTHENTICATION_BACKENDS = ('project_name.wherever.you.put.it.SmartModelBackend',)