Skip to content

Instantly share code, notes, and snippets.

View IdahoEv's full-sized avatar

Evan Dorn IdahoEv

View GitHub Profile
// a function is just a function. By default it has no 'this' and returns nothing
function myFunction() {
this.value = 5;
}
// if I call it, I get nothing back
var obj1 = myFunction(); // obj1 is undefined
// if I call it with 'new', a new empty object is assigned to 'this' and returned to me afterwards
var obj2 = new myFunction(); // obj2 is { value: 5 }
/* eslint-disable flowtype/require-parameter-type */
/* eslint-disable flowtype/require-return-type */
import React, { Component } from 'react';
import { Field } from 'redux-form';
import { reduxForm } from 'redux-form';
/* Trying to use a custom component for a <select>. Can't get it to work with redux-form */
const Select = props => {
const name = props.name || props.input.name;
console.log(`Select ${name} called with `, props);
@IdahoEv
IdahoEv / item.ex
Last active January 20, 2017 01:32
defmodule Tracker.Item do
use Tracker.Web, :model
alias Tracker.Repo
import Ecto.Query
schema "items" do
field :name, :string
field :score, :decimal, virtual: true
has_many :events, Tracker.Event
end
@IdahoEv
IdahoEv / foo.ex
Last active December 3, 2016 15:22
defmodule Foo do
defstruct text: "hello"
end
my_module = Foo
# Next line doesn't work
struct = %my_module{}
def pairwise_sum(target, list)
seen = {}
list.each do |element|
if seen[target - element]
p [element, seen[element]]
else
seen[element] = element
end
end
end
defmodule Collidex.ListDetector do
@moduledoc """
Functions responsible for testing lists of geometric primitives for
collisions.
"""
@doc """
Given two lists `list1` and `list2`, will return a list of collisions
found between any shapes in list1 and any shapes in list2.
"""
@IdahoEv
IdahoEv / comment.md
Last active September 23, 2015 22:22

The code in question looked like this (shortened version):

def count_of_beats_by_kind 
  set = @project.beats
  list = BEAT_KINDS
  list.each do |kind|
    counts[kind] = set.where(:kind => kind).count.to_f
  end
  counts["total"] = set.count.to_f

return counts

@IdahoEv
IdahoEv / What AR thinks the columns are
Created May 22, 2015 22:20
Weird mismatch in columns
(byebug) Profile::Researcher.table_name
"researchers"
(byebug) Profile::Researcher.column_names
["id", "first_name", "last_name", "company", "status", "user_id"]
module Rack::Insight
class EnableButton
include Render
MIME_TYPES = ["text/plain", "text/html", "application/xhtml+xml"]
def initialize(app, insight)
@app = app
@insight = insight
end
// very simple console wrapper to preserve history
(function(){
// Returns a version of obj without functions
// or recursive references. Recursive references
// will blow out the stack when we try to
// serialize.
function strippedObject(obj, cache = []) {
var newObj = {};
for (var property in obj) {