Skip to content

Instantly share code, notes, and snippets.

View marcoow's full-sized avatar
🙈
🙉🙊

Marco Otte-Witte marcoow

🙈
🙉🙊
View GitHub Profile
@marcoow
marcoow / rejection_handler.js
Created June 17, 2013 12:20
custom rejection handler that destroys the session whenever the server returns a 401
DS.rejectionHandler = function(reason) {
if (reason.status === 401) {
App.Auth.destroy();
}
throw reason;
};
@marcoow
marcoow / authenticated_rest_adapter.js
Last active December 18, 2015 14:19
custom REST adapter for ember-data that sends the authentication token in a header
App.AuthenticatedRESTAdapter = DS.RESTAdapter.extend({
ajax: function(url, type, hash) {
hash = hash || {};
hash.headers = hash.headers || {};
hash.headers['X-AUTHENTICATION-TOKEN'] = this.authToken;
return this._super(url, type, hash);
}
});
@marcoow
marcoow / cookie_support.js
Last active December 18, 2015 14:19
storing auth token and account in local cookies (uses https://github.com/carhartl/jquery-cookie)
@marcoow
marcoow / session.json
Created June 17, 2013 12:08
response JSON from /session
{
session: {
auth_token: '<SOME RANDOM AUTH TOKEN>',
account_id: '<ID OF AUTHENTICATED USER>'
}
}
@marcoow
marcoow / sessions_routes.js
Last active December 18, 2015 14:19
ember.js session route that handles login
App.SessionsNewRoute = Ember.Route.extend({
events: {
createSession: function() {
var router = this;
var loginOrEmail = this.controller.get('loginOrEmail');
var password = this.controller.get('password');
if (!Ember.isEmpty(loginOrEmail) && !Ember.isEmpty(password)) {
$.post('/session', {
session: { login_or_email: loginOrEmail, password: password }
}, function(data) {
@marcoow
marcoow / new.js.hbs
Last active December 18, 2015 14:19
ember.js login form
<form>
<label for="loginOrEmail">Login or Email</label>
{{view Ember.TextField valueBinding="loginOrEmail" placeholder="Login or Email"}}
<label for="password">Password</label>
{{view Ember.TextField valueBinding="password" placeholder="Password"}}
<button {{action 'createSession'}}>Login</button>
</form>
require 'net/http'
require 'uri'
lang = 'ruby'
code = 'class Test; end'
response = Net::HTTP.post_form(URI.parse('https://pygments.simplabs.com/'), { 'lang' => lang, 'code' => code })
puts response.body
module Broker
class Server < Goliath::API
use Goliath::Rack::Heartbeat
use Goliath::Rack::SimpleAroundwareFactory, Broker::LoggingAroundware
def response(env)
url = "app_server:3000#{env['REQUEST_URI']}"
method = env['REQUEST_METHOD'].downcase.to_sym
class Product < ActiveRecord::Base
belongs_to :product
include Module.new do
def product=(product)
super
freeze_product_data
product
class Product < ActiveRecord::Base
belongs_to :product
def product=(product)
super
freeze_product_data
product
end