Skip to content

Instantly share code, notes, and snippets.

View upgradingdave's full-sized avatar

Dave Paroulek upgradingdave

View GitHub Profile
@upgradingdave
upgradingdave / day10.clj
Created December 11, 2020 02:09
Advent of Code 2020 Day 10 Part 2 - too slow
(defn find-possibles [j js]
(take-while #(<= % (+ j 3)) js))
(defn possibilities [j js]
(cond
;; we've made it to the end of jolts, this is a possibility
(empty? js)
1
const functions = require('firebase-functions');
// The Firebase Admin SDK to access Cloud Firestore.
const admin = require('firebase-admin');
admin.initializeApp();
function createDB() {
let db = admin.firestore();
let podoDoc = db.collection('android').doc('podo');
@upgradingdave
upgradingdave / core.clj
Last active June 15, 2020 12:36
PurelyFunctional Challenge 382
(ns purelyfun.382.core)
(defn uniques
[values]
(map first (filter #(= (count %) 1) (vals (group-by identity values)))))
@upgradingdave
upgradingdave / 379.clj
Last active May 25, 2020 23:12
PurelyFunctional Issue 379 Challenge
(ns purelyfun.379)
;; My solution to the weekly challenge here:
;; https://purelyfunctional.tv/issues/purelyfunctional-tv-newsletter-379-get-produces-unexpected-behavior-as-expected/
(comment
;; My approach is to use a very basic LR parser.
;; First, I create a nested map datastructure to act as a lookup
@upgradingdave
upgradingdave / gist:68bf9554a92ae520a626190f7d69c9b6
Created August 2, 2018 18:13
Clojure linked list using defrecord
(defrecord ListNode [value next])
(defn add-node [^ListNode curr v]
(if curr
(assoc curr :next (add-node (:next curr) v))
(ListNode. v nil)))
(def result
(loop [l nil i 0]
(if (< i 100000)
@upgradingdave
upgradingdave / functions_vs_methods.js
Last active March 21, 2016 02:17
Javascript methods vs functions vs constructors vs apply
// Javascript uses 4 patterns of invoking a function. These all differ
// in the way that `this` is treated. The 4 patterns are:
// 1. method invocation
// 2. function invocation
// 3. constructor invocation
// 4. apply invocation
// 1. method invocation - When a function is stored as a property of
// an object, it's referred to as a "method" and `this` is bound to
@upgradingdave
upgradingdave / castra.cljs
Last active March 3, 2016 15:54
A version of castra.cljs without jquery
;; Copyright (c) Alan Dipert and Micha Niskin. All rights reserved.
;; The use and distribution terms for this software are covered by the
;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
;; which can be found in the file epl-v10.html at the root of this distribution.
;; By using this software in any fashion, you are agreeing to be bound by
;; the terms of this license.
;; You must not remove this notice, or any other, from this software.
(ns upgradingdave.castra
(:require [cognitect.transit :as t]
[goog.labs.net.xhr :as gxhr])
@upgradingdave
upgradingdave / heap.cpp
Created November 25, 2014 20:21
print a heap
Given an array that looks like this:
[2 4 5 1 2 9 3 8 6 5 2 4 5 1 2 9 3 8 6 5]
This method will print something like this:
2
4 5
1 2 9 3
8 6 5
#include <iostream>
#include <string>
using namespace std;
void underscore2answer(string text, string answer){
int text_idx = 0;
int answer_idx = 0;
for (int text_idx = 0; text_idx<text.length();text_idx++){
if (text[text_idx] == '_'){
@upgradingdave
upgradingdave / permute.cpp
Last active August 29, 2015 14:08
Permute a string
Here's an example of tracing the variables thru the call:
permute(cat)
| word | f | r | i | next | result | res |
|------+---+----+---+------+----------------------------+----------------|
| cat | c | at | 0 | cat | permute(at) = ["at", "ta"] | ["cat", "cta"] |
| cat | | | | act | ... | ... |
permute(at)
| word | f | r | i | next | result | res |