Skip to content

Instantly share code, notes, and snippets.

@addywaddy
addywaddy / Main.elm.diff
Last active August 30, 2018 09:36
Elm loader update for 1.9
diff --git a/app/javascript/Main.elm b/app/javascript/Main.elm
index 7b2be6c..f5c7b74 100644
--- a/app/javascript/Main.elm
+++ b/app/javascript/Main.elm
@@ -1,54 +1,69 @@
module Main exposing (..)
+import Browser
import Html exposing (Html, h1, text)
import Html.Attributes exposing (style)
@addywaddy
addywaddy / gist:b68e9d2c27008f4e03853750a7f26508
Created July 4, 2018 20:41
Extract plain text from MS Word docx files
unzip -p some.docx word/document.xml | sed -e 's/<[^>]\{1,\}>//g; s/[^[:print:]]\{1,\}//g'
@addywaddy
addywaddy / mov-to-gif.md
Last active January 1, 2018 18:49
Converting a screen recording generated using Quick Time to a GIF

Prerequisites

  1. Quick Time
  2. ffmpeg

Record the screen

  1. Open Quick Time
  2. File > New > Screen Recording
  3. Click the red button.
@addywaddy
addywaddy / rails_helper.rb
Created November 14, 2017 09:12
Defining download directory for chrome system specs
# ...
RSpec.configure do |config|
# ...
config.before(:each, type: :system, js: true) do
desired_capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
'chromeOptions' => {
'prefs' => {
'download.default_directory' => Rails.root.join('spec/downloads'),
'download.prompt_for_download' => false,
'plugins.plugins_disabled' => ["Chrome PDF Viewer"]

Keybase proof

I hereby claim:

  • I am addywaddy on github.
  • I am addywaddy (https://keybase.io/addywaddy) on keybase.
  • I have a public key ASCpnhfMfZvFU5Mvy6Pdp7uf3GF6kbFmuPdppWgokbmOpQo

To claim this, I am signing this object:

@addywaddy
addywaddy / nested-idents.cljs
Created February 22, 2016 12:55
Om next nested idents
(def init-data
{:session {:user/id 1
:messages [{:message/id 1}]}
:messages [{:message/id 1 :text "Message 1"}
{:message/id 2 :text "Message 1"}]
:users [{:user/id 1 :email "[email protected]"}
{:user/id 2 :email "[email protected]"}]})
(defui Message
static om/Ident
@addywaddy
addywaddy / gist:14baacff22aa93eaba84
Created November 6, 2014 16:14
Tasks for importing and exporting DB dumps.
namespace :db do
task export: [:environment] do
conn = ActiveRecord::Base.connection_config
cmd = "PGPASSWORD=#{conn[:password]} pg_dump -Fc -h localhost -U #{conn[:username]} #{conn[:database]} > /tmp/#{conn[:database]}.sql"
puts cmd
system cmd
end
task :import => [:environment] do
conn = ActiveRecord::Base.connection_config
@addywaddy
addywaddy / rbenv_schedule.rb
Last active August 29, 2015 14:04
Whenever and Rbenv
# As cron runs with a restricted environment, we need to provide it with the correct path for our ruby
# Define the following jobs:
job_type :rbenv_rake, %Q{export PATH=/usr/local/rbenv/shims:/usr/local/rbenv/bin:$PATH; eval "$(rbenv init -)"; \
cd :path && RAILS_ENV=:environment bundle exec rake :task --silent :output }
job_type :rbenv_runner, %Q{export PATH=/usr/local/rbenv/shims:/usr/local/rbenv/bin:$PATH; eval "$(rbenv init -)"; \
cd :path && bundle exec rails runner -e :environment ':task' :output }
# And then use them in your schedule
(defn foo [first & rest]
(apply bar first rest)
)
(foo :name [:a :b] [:c :d])
;; How can I ensure that bar is called like this:
;; (bar :name [:a :b] [:c :d])
;;
;; and not like this:
;;
@addywaddy
addywaddy / regexp_hash.rb
Created May 22, 2012 07:55
RegexpHash: Hash subclass for building nested regular expressions
class RegexpHash < Hash
def add_word(word, hsh = nil)
hsh ||= self
return unless (word && word.length > 0)
key = word.slice(0..0)
hsh[key] ||= {}
add_word(word.slice(1..-1), hsh[key])
end