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 / gist:969351
Created May 12, 2011 20:18 — forked from Gregg/gist:968534
Code School Screencasting Framework

Screencasting Framework

The following document is a written account of the Code School screencasting framework. It should be used as a refernce of the accompanying screencast on the topic.

Why you should care about screencasting?

You're probably aren't going to take the time to read this document if you're not interested, but there are a lot of nice side effects caused by learning how to create quality screencasts.

  1. Communicating more effectively - At Envy Labs we produce screencasts for our clients all the time. Whether it's demoing a new feature or for a presentation for an invester, they're often much more effective and pleasent than a phone call or screen sharing.
@jswanner
jswanner / migrate.rake
Last active April 1, 2021 22:05
Rolls back migrations in current branch not present in specified branch.
desc 'rolls back migrations in current branch not present in other'
task :rollback_branch_migrations, [:other_branch] do |t, args|
load "#{Dir.pwd}/Rakefile"
branch_migrations = BranchMigrations.new(args.other_branch)
puts ['Rollback the following migrations', branch_migrations, 'y,n? ']
next if %w[no n NO N].include?(STDIN.gets.chomp)
Rake::Task['environment'].invoke
@jswanner
jswanner / nulls_last.rb
Created September 13, 2012 20:03
ActiveRecord Postgres Nulls Last
ActiveSupport.on_load(:active_record) do
module Arel::NullsLastPredications
def nulls_last
Arel::Nodes::NullsLast.new self
end
end
module Arel::Nodes
class NullsLast < Unary
def gsub *args
@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() {
$ chmod +x wc.rb
$ echo "hello, world" | ./wc.rb
1 2 13
$ printf "line 1\nline 2\n" | ./wc.rb
2 4 14
#! /usr/bin/env ruby
require 'bundler/inline'
gemfile do
gem 'rspec', '3.7', require: false
end
class Program
def initialize(input)
$ rspec wc.rb
....
Finished in 0.00348 seconds (files took 0.19061 seconds to load)
4 examples, 0 failures