Skip to content

Instantly share code, notes, and snippets.

require 'uri'
# There's a bug in jboss or torquebox where encoded backslashes in URLs are incorrectly converted into forward slashes.
# This is rack middleware that detects when the original request included a backslash and will correct the env variable
# before forwarding it to the other middleware
# See https://issues.jboss.org/browse/TORQUE-955
class TorqueboxBackslashFixMiddleware
ENCODED_BACKSLASH = "%5C"
@bogdanRada
bogdanRada / Pull-and-Sync-Data-Between-Google-Doc-Spreadsheet-and-MySQL.gs
Created October 5, 2018 13:03
You can pull data from MySQL database to Google doc spreadsheet auto with just click of a button or scheduled time. This is great use for retrieving data in spreadsheet format.
// MySQL to Google Spreadsheet By Pradeep Bheron
// Support and contact at pradeepbheron.com
function myMySQLFetchData() {
var conn = Jdbc.getConnection('jdbc:mysql://127.0.0.1:3306/employee_db', 'username', 'pass'); // Change it as per your database credentials
var stmt = conn.createStatement();
var start = new Date(); // Get script starting time
@bogdanRada
bogdanRada / move_rows.rb
Created October 1, 2018 11:11
move batch rows from fixed batch to all patient cases batch
def move_rows(from_batch_id, to_batch_id = 3539, errors_batch_id: 3558, execute: false, move_rows: :affected)
swap_ids_query = <<SWAP_IDS_QUERY
SELECT
to_br.internal_id,
to_br.service_type,
count(DISTINCT to_br.eligible_batch_id) to_batches_count,
count(DISTINCT from_br.eligible_batch_id) from_batches_count,
GROUP_CONCAT(DISTINCT to_br.id) to_br_ids,
GROUP_CONCAT(DISTINCT from_br.id) from_br_ids,
count(DISTINCT to_br.id) to_br_id_count,
@bogdanRada
bogdanRada / scoped_batches.rb
Created October 1, 2018 08:48
Scoped Batches
module ActiveRecord
module ScopedBatches
def scoped_find_each(options = {})
scoped_find_in_batches(options) do |records|
records.each { |record| yield record }
end
end
def scoped_find_in_batches(options = {})
@bogdanRada
bogdanRada / each_slice.js
Created August 24, 2018 11:30 — forked from SauloSilva/each_slice.js
Each slice javascript
// without callback
Array.prototype.eachSlice = function (size){
this.arr = []
for (var i = 0, l = this.length; i < l; i += size){
this.arr.push(this.slice(i, i + size))
}
return this.arr
};
[1, 2, 3, 4, 5, 6].eachSlice(2)
@bogdanRada
bogdanRada / character_set_and_collation.rb
Created August 14, 2018 13:08 — forked from tjh/character_set_and_collation.rb
Convert all Rails table column collation and character set
#!/usr/bin/env ruby
# Put this file in the root of your Rails project,
# then run it to output the SQL needed to change all
# your tables and columns to the same character set
# and collation.
#
# > ruby character_set_and_collation.rb
DATABASE = ''
@bogdanRada
bogdanRada / httpsig-in-postman-pre-request-script.js
Created August 1, 2018 08:53 — forked from DinoChiesa/httpsig-in-postman-pre-request-script.js
pre-request script for Postman, to perform HttpSignature calculation. Also SHA-256 message digest.
function computeHttpSignature(config, headerHash) {
var template = 'keyId="${keyId}",algorithm="${algorithm}",headers="${headers}",signature="${signature}"',
sig = template;
// compute sig here
var signingBase = '';
config.headers.forEach(function(h){
if (signingBase !== '') { signingBase += '\n'; }
signingBase += h.toLowerCase() + ": " + headerHash[h];
});
@bogdanRada
bogdanRada / postman-hmac-sha256-preq-request.js
Last active August 1, 2018 08:54 — forked from ravikiranj/postman-hmac-sha512-preq-request.js
HMAC SHA512 Authentication Pre-request script for Postman
var index = request.url.indexOf('/');
var uri_path = request.url.substring(index);
var payload = uri_path + request.data;
console.log("Using payload as " + payload)
var hash = CryptoJS.HmacSHA256(payload, environment.secret);
var hashInBase64 = CryptoJS.enc.Hex.stringify(hash);
postman.setGlobalVariable("signature", hashInBase64);
// @see http://gauravds.blogspot.com/2016/06/creating-hmac-in-postman-using-cryptojs.html
@bogdanRada
bogdanRada / openzoom.zsh
Created July 30, 2018 07:07 — forked from brycemcd/openzoom.zsh
Opens a zoom meeting in a browser from the command line
#!/bin/zsh
# Opens a zoom meeting with the name you've given it.
# Drop this script in /usr/local/bin/openzoom
# Invoke with `openzoom meeting_name`
typeset -A meeting
# NOTE: set this hashmap with meeting_name and ids of that meeting
meeting[meeting_name]=123456789
@bogdanRada
bogdanRada / register_chrome_with_window_size.rb
Created July 17, 2018 11:47 — forked from mars/register_chrome_with_window_size.rb
Set window size for Capybara/Selenium/chromedriver
Capybara.register_driver :chrome do |app|
Capybara::Selenium::Driver.new(app,
browser: :chrome,
desired_capabilities: {
"chromeOptions" => {
"args" => %w{ window-size=1024,768 }
}
}
)
end