Skip to content

Instantly share code, notes, and snippets.

@gurix
gurix / output.txt
Last active August 29, 2015 14:10
Perceptron Learning with 3 inputs
1 x0: 1 x1: 0 x2: 1 desired: 1 current: 0 w0: -0.4 w1: 0.5 w2: -0.4 sum: -0.8
w0: -0.1 w2: -0.1
2 x0: 0 x1: 1 x2: 1 desired: 1 current: 1 w0: -0.1 w1: 0.5 w2: -0.1 sum: 0.4
3 x0: 1 x1: 1 x2: 1 desired: 1 current: 1 w0: -0.1 w1: 0.5 w2: -0.1 sum: 0.3
4 x0: 0 x1: 0 x2: 1 desired: 0 current: 0 w0: -0.1 w1: 0.5 w2: -0.1 sum: -0.1
5 x0: 1 x1: 0 x2: 1 desired: 1 current: 0 w0: -0.1 w1: 0.5 w2: -0.1 sum: -0.2
w0: 0.2 w2: -0.4
6 x0: 0 x1: 1 x2: 1 desired: 1 current: 1 w0: 0.2 w1: 0.5 w2: -0.4 sum: 0.1
7 x0: 1 x1: 1 x2: 1 desired: 1 current: 1 w0: 0.2 w1: 0.5 w2: -0.4 sum: 0.3
8 x0: 0 x1: 0 x2: 1 desired: 0 current: 0 w0: 0.2 w1: 0.5 w2: -0.4 sum: -0.4
@gurix
gurix / omniauth_callbacks_controller.rb
Created August 21, 2014 14:36
Sign up via omniauth with diffferent locales
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
def twitter
handle_redirect('devise.twitter_uid', 'Twitter')
end
def facebook
handle_redirect('devise.facebook_data', 'Facebook')
end
private
@gurix
gurix / hstore_pivot.sql
Created April 9, 2014 10:01
Creating a cross tab / pivot table form hstore fields with dynamical column names using in postgresql
DROP TABLE IF EXISTS survey_sessions;
-- Imagine a table with survey sessions
-- token: some id or token to access a survey
-- answers: a key value store for answers
CREATE TABLE survey_sessions (
token text,
answers hstore);
-- We need some data to play with
INSERT INTO survey_sessions (token, answers) VALUES ('9IaxxP', 'a=>1, b=>2');