Skip to content

Instantly share code, notes, and snippets.

View hxegon's full-sized avatar
🐪
Oh Caml my Caml

Cooper LeBrun hxegon

🐪
Oh Caml my Caml
  • Vaudreuil-Dorion, QC
View GitHub Profile
@hxegon
hxegon / toggle_layout.sh
Last active November 23, 2023 06:54
Script to toggle keyboard layouts between qwerty and dvorak in hyprland
#!/usr/bin/env sh
# vi: ft=sh
# Toggle hyprland kb_variant between qwerty and dvorak
# Optional first arg is the path to hyprland.conf
# defaults to ~/.config/hypr/hyprland.conf
#
# Put this in something like ~/.config/hypr/bin/toggle_layout,
# chmod +x it, and add some binding like this:
# bind = $mainMod SHIFT, T, exec, /home/<your_username>/.config/hypr/bin/toggle_layout
@hxegon
hxegon / iteration.cljs
Last active March 11, 2023 17:14
re-frame event loosely mimicking clojure 1.11's iteration
;; recur-event - dispatch vector for when target isn't reached
;; :root-path - Where is this iteration state to be kept in the app-db?
;; :unwrap - pre process step-ret. Identity by default. Example: parse json and get body key of response
;; unwrap output is input for nextf, reachedp, updatef, somep
;; :somep - Are there more items in this request? If not, consider this to be the end of available items
;; :nextf - Get next cursor value
;; :updatef - Update values - takes old values and output of unwrap, update iteration values in app-db
;; :reachedp - Did the cursor reach the desired item? passed ret val of nextf, is nextf by default
(rf/reg-event-fx
::iteration
@hxegon
hxegon / Dockerfile
Last active October 23, 2017 18:49
alpine dockerfile example
# forgive me for any noob stuff, this is like my second dockerfile :P
FROM ruby:2.3-alpine
WORKDIR /app
COPY Gemfile* ./
# the --virtual <name> flag groups packages by name. I use this (sometimes) to remove build deps once everything is installed.
# All bulid stuff in one RUN command to reduce number of image layers
RUN apk update && \
@hxegon
hxegon / longest_increasing_subset.clj
Last active April 22, 2017 00:24
From a list of integers, get the longest increasing subset. This would solve 4clojure problem 53 if 4clojure didn't use clojure 1.4. dedupe is from 1.7 on
(fn [coll]
(let [parduction-by (fn [predf coll] (->> (partition 2 1 coll) (partition-by predf) (filter #(some predf %)) (map #(mapcat identity %)) (map dedupe)))
inc? (fn [[a b]] (= (inc a) b))]
(->> (parduction-by inc? coll) (sort-by count) last)))
;; for an example of what parduction-by does, it's basically a combination of partition-by, reduce and filter
;; I'd like to take out the filter aspect and leave that for the user.
(parduction-by inc? '(1 0 1 2 3 0 4 5)) ;; => '((0 1 2 3) (4 5))
@hxegon
hxegon / browser.rb
Last active March 24, 2017 16:34
possible object design for ascio's browser problem [WIP]
# Roughly based on my https://github.com/hxegon/aok_product/blob/e417b2bc6df9d772d09bb025e502c46a548d55e9/lib/extractor.rb
# This possibley has a bug in Browser, with @@actions being a class instance var. Might be fixable by changing @browsers to
# class inst var, and adding during #add_action instead of pushing it off too #initialize
class Implementations
# Keeps track of what browsers are available, and what their actions are.
# default is what get returned when nothing matches the action_list you give #for
def initialize(actions=[], default:nil)
# actions format: [(class_name, action_name)], good candidate for class extraction or just a struct
@default = default
actions.each { |(action_name, class_name| add_action(class_name, action_name) }
class SomeClass
def initialize(current_account, form, request)
@form = form
@request = request
end
def call
if invalid?
form.errors.add(:credentials, :invalid)
return broadcast(:invalid, form)
@hxegon
hxegon / Gemfile
Last active January 22, 2016 05:06
Why does this give me VCR::Errors::UnhandledHTTPRequestError
source 'https://rubygems.org'
group :development do
gem 'rake'
gem 'guard', require: false
gem 'guard-rspec', require: false
end
group :development, :testing do
gem 'dotenv'
@hxegon
hxegon / example_stub_problem.rb
Created December 8, 2015 19:46
Having some trouble testing module instance method behavior.
module Foo
def bar
"#{to_s} whizbang"
end
end
describe Foo do
describe "#bar" do
it "works" do
base = Class.new { include Foo }
def map_product_strings(prod_val, &block)
# product hash -> product hash with strings changed through block
case prod_val
when Hash
Hash[prod_val.map {|key, val| [key, map_product_strings(val, &block)]}]
when Array
prod_val.map { |v| map_product_strings(v, &block) }
when String
GIT
remote: git://github.com/spree/spree_auth_devise.git
revision: b554f307e5aa887110a70d54f8967c284f881375
branch: 3-0-stable
specs:
spree_auth_devise (3.0.0)
devise (~> 3.4.1)
devise-encryptable (= 0.1.2)
json
multi_json