Skip to content

Instantly share code, notes, and snippets.

@deevis
deevis / gist:b2863c21fb892519452a18a65d7a4229
Created October 3, 2019 17:08
Check for url responsiveness/timeout/connectivity
for i in `seq -f "%02g" 1 10`; do echo -n "Attempt $i:"; curl --max-time 5 https://your.website.com/login 2>/dev/null | wc; done
# Output will be something like:
# Attempt 01: 18 145 10011
# Attempt 02: 18 145 10011
# Attempt 03: 0 0 0
# Attempt 04: 0 0 0
# Attempt 05: 0 0 0
# Attempt 06: 0 0 0
# Attempt 07: 18 145 10011
@deevis
deevis / gist:1a45ab7f55ea514d2a2c8fa3a27ec271
Last active August 15, 2019 20:30
Show create counts by FactoryBot
#
# lib/factory_bot/strategy/create.rb
#
# coloring from: http://graysoftinc.com/terminal-tricks/random-access-terminal
#
module FactoryBot
module Strategy
class Create
@@__counts = Hash.new(0)
CSI = "\e["
hexdump = ->(bytes,width) {bytes.each_with_index{|b,i| print " [#{i.to_s(16).upcase.rjust(2,'0')}] "
if i%width==0; print "#{b.to_s(16).upcase.rjust(2,'0')} "; puts "" if (i+1) % width == 0};nil}
@deevis
deevis / decimal_dump.rb
Created August 5, 2019 21:52
Takes a byte[] and a width to set number of display columns and dumps the bytes out in a grid
decdump = ->(bytes,width) {bytes.each_with_index{|b,i| print " [#{i.to_s.rjust(3,' ')}] "
if i%width==0; print "#{b.to_s.rjust(3,' ')} "; puts "" if (i+1) % width == 0};nil}
@deevis
deevis / cryptomancer.rb
Last active July 17, 2019 21:40
Ruby AES Cryptography
require 'openssl'
require 'stringio'
require 'base64'
class Cryptomancer
def initialize(alg: nil, key: nil)
@alg = alg || "AES-256-CBC"
@key = key || "1234567890123456ASDFasdfASDFasdf" # 32 byte key for 256-bit AES (16 bytes for 128-bit...)
end
@deevis
deevis / gist:ddf95d16c1d056e085499d35b9d1b4e8
Created April 23, 2019 15:50
Rails startup initializers play-by-play with engines
Running initializer: set_load_path
Running initializer: set_autoload_paths
Running initializer: add_routing_paths
Running initializer: add_locales
Running initializer: add_locales
Running initializer: add_view_paths
Running initializer: load_environment_config
kringle/config/environments/development.rb
Running initializer: load_environment_hook
Running initializer: load_active_support
@deevis
deevis / query.rb
Created January 31, 2019 16:32
MongoDB group aggregation with count and sort
q = [
{ "$match" => { "created_at" => { "$gte" => 60.days.ago, "$lte" => 0.days.ago }}},
{ "$group" => { _id: {
'year' => {'$year' => "$created_at"},
'month' => {'$month' => "$created_at"},
'day' => {'$dayOfMonth' => "$created_at"},
"errorable_type" => "$errorable_type",
"error_class" => "$error_class"
},
count: { "$sum" => 1 }
http://es-cerebro.apps.verisys.com:9222/cerebro_elicense/_search?size=100&q=%2Bepmatching_name%3Awalmart*+%2Bname%3A*10-3384*
@deevis
deevis / gist:2f972979cd821d5d46a2f97765ad3c3b
Last active May 25, 2018 17:49
Remove monitoring indexes from Elasticsearch - remove 'head' to delete them all
for index in `curl http://es-cerebro.apps.domain.com:9200/_cat/indices | grep "monitoring-es-6" | sort | head | sed 's/-.\{11\}\).*1 1.*/\1/g'`; do echo -e "\nDeleting: $index"; curl -X DELETE "http://es-cerebro.apps.verisys.com:9200/$index"; done
match (npi:Registration{label:'NPI:1407098122'}), (m) where (m:Sanction or m:License or m:Registration or m:Ssn) with npi,m match p=allShortestPaths((npi)-[:FOUND_IN*0..6]-(m)) where NONE( x in nodes(p) where labels(x) = ['ExternalDatum'] and x.source = 'piidat' and x.source_id <> '61474244') unwind (nodes(p)) as node match(node)-[found_in:FOUND_IN]->(datum) where not (node:ExternalDatum) return distinct labels(node), node, collect(distinct found_in.payload) order by labels(node)