Skip to content

Instantly share code, notes, and snippets.

Joe Yates joeyates

Block or report user

Report or block joeyates

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@joeyates
joeyates / writable.md
Created Oct 7, 2018
Gist Writable URL
View writable.md
  • get the Repo's hash from the Gist URL
  • the writable URL is:
git@gist.github.com:<hash>
@joeyates
joeyates / chewy-date-range-query.rb
Created Apr 10, 2018
Use Chewy to extract a date range
View chewy-date-range-query.rb
bars =
FooIndex::Bar.all.
query(range: {start_date: {lt: "2018-03-31"}}).
query(range: {end_date: {gt: "2018-03-31"}}).
load.to_a
@joeyates
joeyates / rename_media.rb
Last active Feb 18, 2018
Classify Photos and Movies Downloaded from Android Phone into nested directories by Year, Month and Day
View rename_media.rb
#!/usr/bin/env ruby
require "fileutils"
require "rake"
ROOT = File.expand_path(ARGV[0] || ".", Dir.pwd)
ANDROID_MATCH = /
\/ # The whole file name
(IMG|VID) # starts with an image or film indicator.
_ # An underscore is followed by
@joeyates
joeyates / certificate-expiry
Last active Oct 20, 2018
Get the expiry date for an online TLS/SSL certificate
View certificate-expiry
#!/usr/bin/env bash
hostname=$1
online-certificate $hostname | \
openssl x509 -inform pem -noout -enddate
View datocms_item_upload_with_image_field.sh
# Upload an item with an image field
export DATO_CMS_API=https://site-api.datocms.com
export DATO_CMS_API_TOKEN={{your read-write API token}}
# Get info about your Models (item-types):
curl \
-H "Authorization: Api-Key $DATO_CMS_API_TOKEN" \
-H "Accept: application/json" \
@joeyates
joeyates / merge_keyword_lists_and_maps.ex
Created Jul 9, 2017
Merge Elixir keyword lists and maps
View merge_keyword_lists_and_maps.ex
defp combine(list1, list2) do
Keyword.merge(keyword_list(list1), keyword_list(list2), fn _k, _v1, v2 ->
v2
end)
end
def keyword_pair({key, value}) when is_atom(key) do
{key, value}
end
def keyword_pair({key, value}) do
@joeyates
joeyates / extend_jsx_encoder.ex
Last active Jul 10, 2017
JSON Serialization of Elixir 2-ples
View extend_jsx_encoder.ex
defimpl JSX.Encoder, for: Tuple do
def json({__t1, __t2}) when is_list(i1) do
[:start_object, "__t1", __t1, "__t2", JSX.encode!(__t2), :end_object]
end
def json({__t1, __t2}) do
[:start_object, "__t1", __t2, "tuple_list", __t2, :end_object]
end
end
@joeyates
joeyates / .rubocop.yaml
Last active Dec 7, 2018
Cantiere Creativo Rubocop Overrides
View .rubocop.yaml
require: rubocop-rspec
AllCops:
Exclude:
- "bin/**/*"
- ".bundle/**/*"
- "bundle/**/*"
- "db/schema.rb"
- "node_modules/**/*"
@joeyates
joeyates / history_unlisten.js
Created May 2, 2017
How does React Router 4's History Class Handle Unlisten?
View history_unlisten.js
class MyHistory {
constructor(...args) {
this.callback = null;
}
listen(callback) {
console.log("listen");
this.callback = callback;
return () => { this.unlisten() };
}
@joeyates
joeyates / subset-sum.rb
Created Apr 29, 2017
Solve the Subset Sum Problem in Ruby using Dynamic Programming
View subset-sum.rb
def dump_table(sums)
sums.each.with_index { |row, sum| puts "#{sum}: #{row.inspect}" }
end
def solvable?(set, size, sum)
sums = (0 .. sum).map do |i|
(0 .. size).map do |j|
nil
end
end
You can’t perform that action at this time.