Skip to content

Instantly share code, notes, and snippets.

View deanmarano's full-sized avatar
🦏

Dean Marano deanmarano

🦏
View GitHub Profile
@deanmarano
deanmarano / unshorten.js
Created May 5, 2012 17:53
Node.js URL unshortening function
var http = require("http"),
url = require("url");
function unshortenUrl(unshortedUrl, returnFunction) {
var urlObj = url.parse(unshortedUrl);
var options = {
host: urlObj.host,
port: urlObj.port,
path: urlObj.pathname
};
-5-----0--0--5-----0-
-7--6--5--5--7--3--5-
-6--7--6--6--6--4--6-
-7--7--7--5--7--4--7-
-5--x--x--x--5--x--x-
----7--5--5-----3--5-
{:ssl-client-cert nil, :remote-addr \"127.0.0.1\", :scheme :http, :context \"/file-sharing-service/files\", :multipart-params {}, :request-method :post, :query-string \"\", :route-params {}, :content-type \"text/plain; charset=UTF-8\", :path-info \"/\", :uri \"/file-sharing-service/files\", :server-name \"accounting-app1-staging.snc1\", :params {}, :headers {\"user-agent\" \"Apache-HttpClient/4.2.2 (java 1.5)\", \"host\" \"accounting-app1-staging.snc1:5000\", \"content-type\" \"text/plain; charset=UTF-8\", \"content-length\" \"8347\", \"user-uuid\" \"26c62164-d71f-48e8-8854-e650f36620b8\", \"accept-encoding\" \"gzip, deflate\", \"connection\" \"close\"}, :content-length 8347, :server-port 5000, :character-encoding \"UTF-8\", :body #<ReusableInputStream org.immutant.web.ReusableInputStream@5de69e66>}
{:ssl-client-cert nil, :remote-addr \"10.20.32.17\", :scheme :http, :context \"/file-sharing-service/files\", :multipart-params {\"file-data\" {:size 8125, :tempfile #<File /tmp/ring-multipart-6304585165691814722
{{#link-to path object tagName='li'}}
{{#link-to path object}}
{{yield}}
{{/link-to}}
{{/link-to}}
App.FormRoute = Ember.Route.extend
model: (params)-> @store.get('form', params.id)
renderTemplate: (controller, model)->
this.render "forms/#{model.get('formVersion')}/#{model.get('formName')}"
@deanmarano
deanmarano / gist:58d65bbef6c1cc475dc6
Last active August 29, 2015 14:04
Authorized Routes
AuthRoute = Ember.Route.extend
authorize: (->
@transitionTo 'login' unless @modelFor('application')
).on('willTransition')
## Which is the same as....
AuthRoute = Ember.Route.extend
willTransition: ->
@deanmarano
deanmarano / file-input.js
Created September 8, 2014 20:50
File Input Ember Component
import Ember from 'ember';
export default Ember.Component.extend({
tagName: 'input',
attributeBindings: ['type', 'accept', 'multiple'],
type: 'file',
multiple: false,
initialize: function() {
this.$().on('change', function(e) {
this.sendAction('on-change', e.currentTarget.files);
@deanmarano
deanmarano / select2component.js
Last active August 29, 2015 14:06
Globals Version of Select2Component
var get = Ember.get;
var run = Ember.run;
/**
* Ember select-2 component wrapping the jQuery select2 plugin while
* respecting Ember data bindings and getter/setter methods on the content.
*
* Terminology:
* - Value: The currently selected value(s). Propagated to controllers etc.
* through the "value=..."" binding. Types:
@deanmarano
deanmarano / answer.js
Last active August 29, 2015 14:07
Machine Learning 4.2
"// noprotect";
var a = function() {
'use strict';
var examples = [
{inputs: {a: -1, b: -1}, output: -1},
{inputs: {a: -1, b: 1}, output: -1},
{inputs: {a: 1, b: -1}, output: 1},
{inputs: {a: 1, b: 1}, output: -1},
];
@deanmarano
deanmarano / gist:8dffa1f19469693faf0a
Created October 12, 2014 03:15
Additional weights.
[
{
"w0": -0.7201748196966946,
"w1": 0.5520502417348325,
"w2": -0.6326597002334893
},
{
"w0": -0.3573158294893801,
"w1": 0.8063981863670051,
"w2": -0.53787044249475