Skip to content

Instantly share code, notes, and snippets.

View tadast's full-sized avatar

Tadas Tamošauskas tadast

View GitHub Profile
# As per https://github.com/alphasights/guides/pull/14
# Instead of
$ ->
if $('.js_money_index').length
# all your page-specific logic
# Use a [dispatcher](https://coderwall.com/p/mhvucw) with
# controllers/money_controller.js.coffee
def without_delayed_job &block
@old_behaviour = Delayed::Worker.delay_jobs
Delayed::Worker.delay_jobs = false
yield
Delayed::Worker.delay_jobs = @old_behaviour
end
### Usage
describe 'stuff' do
without_delayed_job do
[94] pry(main)> WHATEVER = {a: [{x: :boom1, z: :boom2}]}.freeze
=> {:a=>[{:x=>:boom1, :z=>:boom2}]}
[95] pry(main)> WHATEVER.clone[:a].first[:x] = :wtf
=> :wtf
[96] pry(main)> WHATEVER[:a].first[:x]
=> :wtf
@tadast
tadast / specialist-publisher-schema-to-rumager.rb
Created April 29, 2015 13:41
Helper script to convert govuk specialist-publisher schema to rumager document schema
json = File.read("path/to/specialist-publisher/schema")
publisher_schema = JSON.parse(json)
fields = publisher_schema['facets'].map{|x| x['key']}
allowed_values = {}
publisher_schema['facets'].each do |facet|
allowed_values[facet['key']] = facet["allowed_values"]
end
@tadast
tadast / unused_yam_keys.rb
Last active August 29, 2015 14:21
Unused YAML keys
def find_keys(hash)
hash.flat_map do |key, value|
if value.is_a?(Hash)
find_keys(value)
else
key
end
end
end
@tadast
tadast / public_pgp_key
Created June 1, 2015 18:34
My public PGP key
-----BEGIN PGP PUBLIC KEY BLOCK-----
mQINBFVsoucBEACcPaABLP8Hm6b0R5wcZjsLsyTfrgGwC1mKsGSvoFa8Lu4d9moa
xsyWWO1NdIMMB7UNtlB1sbnFI0mkAiZoRVpk+hdYx9UvPup/exfbsKZWMG2srCvJ
cjL36X5jeGbu3X/78zAlPXlKhvJLf1i+8aMgQheO6He+D8Xu5G1QrCqYPaoEWgER
xQrUxu01S25ziwaf/7VvY3C35hKrQL7JG4N1mOL+QjxMRIzrVXe7mL7Igm7rT5Oz
tQtgfeMc4piTKQaztNbP+Yj+6LdoqeIzs3NWlFxfSqYw2qWrDIAqJlfpwMn/MWGN
r/8skOuCjBYPffDgngayAJrNhjeTlY5u++A41Cx84NhnMH93WpZd+Q7ga12QvRPc
U5/F2IBj/8eaSucKrgOL1KREo2JLS+8/Xp8lgJJNDzRkWhfMAqJnz7F8UwJs3DNW
XkLgKBxZobwztoxVWXgLhm78hwQ1vJLQbGlcFM9wbJzuLLRONniK0Rhx4Kuu0Zn2
@tadast
tadast / README.md
Last active August 29, 2015 14:25 — forked from chrisroos/README.md
Spike into ways of visualising Smart Answers

The print_graph method displays the Smart Answer as a tree.

The print_questions_and_possible_next_nodes method displays the questions and their possible next nodes.

The extraction of possible next nodes is horrible in the case where the Smart Answer uses the block syntax of next_node. I'm getting the source of the block and extracting things that look like symbols.

@tadast
tadast / sm-prototype-hierarchy-crawler.rb
Last active November 9, 2015 13:56
Service manual prototype hierarchy crawler
require 'nokogiri'
require 'open-uri'
require 'pry'
require 'yaml'
class Crawl
def initialize(start_url = "http://sm-11.herokuapp.com")
@start_url = start_url
@guides = []
end
@tadast
tadast / dynamoid_reset.rb
Created September 8, 2016 15:02
Dynamoid test database cleaner
# Prevent wiping out data in non-test environments
raise "Test should be run in 'test' environment only" if Rails.env != 'test'
module DynamoidReset
def self.all
Dynamoid.adapter.list_tables.each do |table|
# Only delete tables in our namespace
if table =~ /^#{Dynamoid::Config.namespace}/
Dynamoid.adapter.delete_table(table)
end
@tadast
tadast / json_api_to_graphviz.js
Created November 19, 2016 16:22
This is a script to take in a {json:api} document (jsonapi.org) and generate a visual graph (http://www.graphviz.org) representation of it
/*
This is a script to take in a {json:api} document (jsonapi.org)
and generate a graphviz (http://www.graphviz.org) representation of it.
Usage:
> node <this_file>
then copy and paste the output to some graphviz parser
e.g. http://www.webgraphviz.com or http://gravizo.com
*/