Skip to content

Instantly share code, notes, and snippets.

Carsten Nielsen heycarsten

Block or report user

Report or block heycarsten

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View lcbapi-python3.py
# 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"'
View keybase.md

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:

View controllers.application.js
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 Aug 29, 2015
Aliasing Ember properties depending on existence of other properties
View example.html
<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 Dec 23, 2015
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!
View README.md

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 Sep 10, 2013
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.
View ember.computed.stored.js
/*
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 Mar 12, 2019
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.
View ember.computed.timer.js
/*
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 Apr 15, 2013
My answers to some questions from @hvt on Twitter about LCBO API and Ruby.
View answer.md

@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 Aug 21, 2017
Dramatically clean up and jazzify your Capistrano output.
View jazzy-cap.md

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 Aug 29, 2012
Underscore's debounce and limit as Function prototypes.
View bounce.js
// 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() {
You can’t perform that action at this time.