Skip to content

Instantly share code, notes, and snippets.

View kevin-cantwell's full-sized avatar
🙃
cOmpUTerZ

Kevin Cantwell kevin-cantwell

🙃
cOmpUTerZ
View GitHub Profile

Keybase proof

I hereby claim:

  • I am kevin-cantwell on github.
  • I am kvn (https://keybase.io/kvn) on keybase.
  • I have a public key whose fingerprint is B4CD E7D8 1A51 4507 F4E4 617F 0D83 475C EA4A 2B28

To claim this, I am signing this object:

package myjson
import (
"fmt"
"strings"
)
type JsonData map[string]interface{}
func (d JsonData) Int64(dotPath string) (int64, error) {
class Budget < ActiveRecord::Base
attr_accessible :budget, :expenses, :start_date, :end_date, :purchases_attributes
has_many :purchases
accepts_nested_attributes_for :purchases, :allow_destroy => true
def perdiem
if remaining_days > 0
((projected_spend_so_far - actual_spend_so_far) / remaining_days) + initial_perdiem
else
class BulkPrice
attr_accessor :quantity, :price
def initialize(quantity, price)
@quantity = quantity
@price = price
end
def price_per_item
price / quantity
end
end
@kevin-cantwell
kevin-cantwell / v2_api_mock.json
Last active August 29, 2015 14:03
Update this gist to give yourself whatever api response you wish.
{
"years": [
{
"year_month_day_key": "20130118",
"weather_summary": "86°F ☀️",
"user_contents": [
{
"id": "ftp:1203139203:910239123:912039:9231231",
"share": {
"prefill": "Exactly 1 year ago today! (via timehop.com)",
@kevin-cantwell
kevin-cantwell / goshim.md
Last active August 29, 2015 14:03
Philosophy of a Go dependency management system.

Goshim: Building a Better Go Dependency Management Tool

Go dependency management is essentially non-existent; this is known. It is also a source of frustration for many in the Go community. The standard Go tools are generally awesome, but the closest thing to dependency management Go provides out of the box is that go get will prefer VCS tags corresponding to the current go version. Afaik, nobody respects (or is even aware of) this convention. This is not entirely surprising, as Rob Pike himself has said that depedency management is a problem left for the community to solve. In fact, the reason why import statements are constructed with a string argument is to allow future support for arbitrary syntactic choices in specifying dependencies. I suspect that when the compiler is fully rewritten in Go, the community will jump at the chance to submit pull requests that support package versioning. Until then, we must build tools to help us strictly define our depe

@kevin-cantwell
kevin-cantwell / wedding_push.rb
Created October 18, 2014 16:01
Push to Benny & Laura's friends
four_pm = Time.parse('2014-10-18 20:00:00 +0000') # 4pm
benny = User.find(1)
laura = User.find(26)
friends << benny
friends << laura
friends += benny.friends_on_timehop;0
friends += laura.friends_on_timehop;0
friends.map do |friend|
notif = PushNotification.new(friend, PushReference.new(:blank_ref, :blank_id))
@kevin-cantwell
kevin-cantwell / example.go
Created November 14, 2014 22:31
v2 server example
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"github.com/timehop/services"
)
// Limits concurrent tasks to a limit of n. If limit is
// reached, return error instead of running task
type RateLimiter struct {
MaxConcurrent int
// Add whatever you need
taskChan chan struct{}
}
func (l *RateLimiter) Limit(task func()) error {
select {
package main
import (
"fmt"
"net/http"
"io/ioutil"
)
const workers int 3