Skip to content

Instantly share code, notes, and snippets.

@jswanner
jswanner / 1-parser.ex
Last active December 3, 2023 00:17 — forked from faried/day2parser.ex
AoC 2023 Day 2 NimbleParsec Parser
defmodule Parser do
import NimbleParsec
game_id = ignore(string("Game ")) |> integer(min: 1, max: 4) |> unwrap_and_tag(:id)
red = replace(string("red"), :red)
green = replace(string("green"), :green)
blue = replace(string("blue"), :blue)
color = choice([red, green, blue])
defmodule Replacer do
import NimbleParsec
one = string("o") |> lookahead(string("ne")) |> replace("1")
two = string("t") |> lookahead(string("wo")) |> replace("2")
three = string("t") |> lookahead(string("hree")) |> replace("3")
four = string("f") |> lookahead(string("our")) |> replace("4")
five = string("f") |> lookahead(string("ive")) |> replace("5")
six = string("s") |> lookahead(string("ix")) |> replace("6")
seven = string("s") |> lookahead(string("even")) |> replace("7")
eight = string("e") |> lookahead(string("ight")) |> replace("8")
@jswanner
jswanner / phx-liveview-single-file-filter-columns.exs
Last active June 23, 2023 23:36
Single-file Phoenix LiveView application with user-selectable table columns
signing_salt = :crypto.strong_rand_bytes(8) |> Base.encode16()
secret_base = :crypto.strong_rand_bytes(32) |> Base.encode16()
Application.put_env(:phoenix, :json_library, Jason)
Application.put_env(:sample, SamplePhoenix.Endpoint,
adapter: Bandit.PhoenixAdapter,
http: [
ip: {127, 0, 0, 1},
port: String.to_integer(System.get_env("PORT") || "4000")
@jswanner
jswanner / components.video-js.js
Last active August 29, 2018 16:43
p3sdk-test
import Ember from 'ember';
export default Ember.Component.extend({
didInsertElement: function() {
this._super();
this.player = videojs(this.$('video')[0], null, function() {
this.play();
});
},
didRender: function() {
#! /usr/bin/env ruby
require 'bundler/inline'
gemfile do
gem 'rspec', '3.7', require: false
end
class Program
def initialize(input)
$ chmod +x wc.rb
$ echo "hello, world" | ./wc.rb
1 2 13
$ printf "line 1\nline 2\n" | ./wc.rb
2 4 14
$ rspec wc.rb
....
Finished in 0.00348 seconds (files took 0.19061 seconds to load)
4 examples, 0 failures
# script logic
if $PROGRAM_NAME == __FILE__
# the script itself is being executed
exit
end
require 'rspec'
RSpec.describe 'the script' do
require 'bundler/inline'
gemfile do
gem 'rspec', '3.7', require: false
end

Keybase proof

I hereby claim:

  • I am jswanner on github.
  • I am jswanner (https://keybase.io/jswanner) on keybase.
  • I have a public key whose fingerprint is 1140 8F9C EAD0 C993 1C96 63E6 C154 4A94 D2DC 2F30

To claim this, I am signing this object: