Skip to content

Instantly share code, notes, and snippets.

View elderbas's full-sized avatar

brian schermerhorn elderbas

View GitHub Profile
@elderbas
elderbas / 0_reuse_code.js
Created June 3, 2016 11:54
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@elderbas
elderbas / angularjs_directive_attribute_explanation.md
Created July 18, 2016 05:45 — forked from CMCDragonkai/angularjs_directive_attribute_explanation.md
JS: AngularJS Directive Attribute Binding Explanation

AngularJS Directive Attribute Binding Explanation

When using directives, you often need to pass parameters to the directive. This can be done in several ways. The first 3 can be used whether scope is true or false. This is still a WIP, so validate for yourself.

  1. Raw Attribute Strings

    <div my-directive="some string" another-param="another string"></div>
@elderbas
elderbas / person.ex
Created December 31, 2017 02:37
Person module
defmodule MyApp.Person do
use MyApp.Web, :model
schema "people" do
field :name, :string
timestamps()
end
@doc """
@elderbas
elderbas / person_controller.ex
Created December 31, 2017 02:52
Inserting Multiple Changesets Into Database - create controller example
...
def create(conn, %{"person" => params}) do
changeset = Person.changeset(%Person{}, class_params)
case Repo.insert(changeset) do
{:ok, person} ->
conn
|> put_status(:created)
|> render("show.json", person: person)
@elderbas
elderbas / people_names.json
Last active December 31, 2017 03:40
Inserting Multiple Changesets Into Database - people json examples
{
"people": [
{"name": "Peter Hamilton"},
{"name": "John Smith"},
{"name": "Edward James"}
]
}
@elderbas
elderbas / class_controller.ex
Last active April 5, 2024 03:35
Elixir — Inserting Multiple Changesets Into Database - create batch
def create_batch(conn, %{"people" => people_params}) do
changesets = Enum.map(people_params, fn class ->
Person.changeset(%Person{}, person)
end)
result = changesets
|> Enum.with_index()
|> Enum.reduce(Ecto.Multi.new(), fn ({changeset, index}, multi) ->
Ecto.Multi.insert(multi, Integer.to_string(index), changeset)
end)
@elderbas
elderbas / ExistenceDictionary.js
Created July 27, 2018 16:54
ExistenceDictionary
class ExistenceDictionary {
constructor(valsToAdd = []) {
this.store = {};
valsToAdd.forEach((val) => {
this.store[val] = true;
})
}
exists(val) {
@elderbas
elderbas / hr_algo_ds_heuristics.md
Last active November 12, 2020 22:34
heuristics for the festival

Honestly I'm not sure which of these would perform best (since some of them might be overfitted for the datasets is aw), but since they each seem pretty reasonable for performance, I could run all 3 in parallel and just pick the one with the most desired result, and get rid of the one that is logged to the worst performance.


Get your bread, Build the sandwich (start outside, fill in left to right)

Find the event that starts the earliest in the day, tie breaker goes to the event that has less events occurring in the day (remove from further selection)

Find the event that starts the latest in the day, while still being later than the first event, tie breaker goes to the event that has less events occurring in the day

// pre-process the lines of text into Array<Array<int>>;
const ballotsPreProcess = [
[1, 2, 3],
[2, 1, 3],
[2, 3, 1],
[1, 2, 3],
[3, 1, 2],
];
// also parse the lines of text into the respectiveCandidate names
@elderbas
elderbas / create_modify_snippets.js
Created November 17, 2020 22:25
rabbit mq location create and modify example snippets
#!/usr/bin/env node
const amqp = require('amqplib/callback_api');
const RABBIT_MQ_EXCHANGE_TYPES = {
FANOUT: 'fanout',
};
function consumePublishedCreationLocation(exchangeName, consumeCb) {
amqp.connect('amqp://localhost', function(error0, connection) {