Skip to content

Instantly share code, notes, and snippets.

View heycarsten's full-sized avatar

Carsten Nielsen heycarsten

View GitHub Profile
# Python 3.6.1
from urllib.request import urlopen, Request
import json
url = 'http://lcboapi.com/products?q=gose'
req = Request(url)
req.add_header(
'Authorization', 'Token token="YOUR_API_KEY_HERE"'

Keybase proof

I hereby claim:

  • I am heycarsten on github.
  • I am heycarsten (https://keybase.io/heycarsten) on keybase.
  • I have a public key ASBliap-zC_0iOy4RIGc-xRsZfZxHzhZ_d-hFF2JwwUDkwo

To claim this, I am signing this object:

import Ember from 'ember';
import FSM from 'ember-fsm';
const WAIT_TIMES = {
'red': 5000,
'amber': 3500,
'green': 6500
};
export default Ember.Controller.extend(FSM.Stateful, {
@heycarsten
heycarsten / example.html
Last active August 29, 2015 14:11
Aliasing Ember properties depending on existence of other properties
<html>
<head>
<title>Learnin'</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/normalize/3.0.1/normalize.css" rel="stylesheet">
<style>
body {
margin: 30px auto;
width: 600px;
}
@heycarsten
heycarsten / README.md
Last active December 23, 2015 12:59
Ember-Validate: This is an initial spike for an approach to validations in Ember, it's extracted from an app I'm building and it works for me in my current use-case. I plan on developing this into a proper, tested library soon, but until then, I thought I'd share!

Ember-Validate

I've had to tackle the client validations problem in almost every Ember app I've ever written, and I've done it in a bunch of different ways. This is the way I ended up liking most. There are a few things that I really wanted to have in a validation framework:

  • Not tied to models or any modelling framework
  • Promise-based
  • Not reliant on extending Ember itself
@heycarsten
heycarsten / ember.computed.stored.js
Created September 10, 2013 15:03
Creates a computed property that persists into local storage, all instances share the same value for the same property, intended to be used for controllers.
/*
Creates a computed property that persists into local storage, all
instances share the same value for the same property.
App.AuthController = Ember.Controller.extend({
token: Em.computed.stored()
});
controller = App.__container__.lookup('controller:auth')
contorller.set('token', 'abc123foo456bar')
@heycarsten
heycarsten / ember.computed.timer.js
Last active March 12, 2019 05:33
Creates a computed property that automatically increments itself at the specified interval in milliseconds. Useful when used as a dependent property to properties that need to changed as time progresses.
/*
Creates a computed property that automatically increments itself at the
specified interval in milliseconds. Useful when used as a dependent
property to properties that need to changed based on time.
App.PostController = Ember.ObjectController.extend({
'@timer': Ember.computed.timer(1000),
sinceCreated: function() {
return new Date().getTime() - this.get('createdAt').getTime();
@heycarsten
heycarsten / answer.md
Created April 15, 2013 16:46
My answers to some questions from @hvt on Twitter about LCBO API and Ruby.

@hvt asks: How’ you create your JSON structure? How did you parse LCBO data to show “result”:{..} KVPs Working off an HTML file currently

How'd you create your JSON structure?

I build a hash in Ruby and then serialize it to JSON and send that to the client. Here's an extremely basic example of this in a Rails controller:

class ProductsController < ApplicationController

 def index
@heycarsten
heycarsten / jazzy-cap.md
Last active August 21, 2017 19:05
Dramatically clean up and jazzify your Capistrano output.

Jazzy Capistrano Output

screenshot

Place the contents below in a file at config/deploy/ext/jazzy.rb:

# coding: utf-8
unless ENV['UNJAZZY']
  STDOUT.sync
@heycarsten
heycarsten / bounce.js
Created August 29, 2012 03:21
Underscore's debounce and limit as Function prototypes.
// These are yoinked from Underscore.js but are added to the function prototype
// so that we can ruin the world.
(function() {
var debounce, throttle;
debounce = function(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {