This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'csv' | |
SOURCE_CSV = "data.csv" | |
OUTPUT_SQL = "#{Time.now.to_a.first(6).reverse.join}.sql" | |
OUTPUT_DB = OUTPUT_SQL + ".db" | |
data_array = CSV.read(SOURCE_CSV, :quote_char => "'", :col_sep =>',', :row_sep =>:auto) | |
header_array = data_array.delete_at(0).map { |h| h.downcase.gsub(" ", "_") } | |
header_string = header_array.join(", ") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
def run max | |
return unless max > 1 | |
return (2 .. max).inject([]) do |r, i| | |
if i.even? | |
r << i if i == 2 | |
else | |
composite = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'yaml' | |
yaml = <<yaml | |
defaults: &defaults | |
cool: | |
bang: wow | |
fruit: apple | |
development: | |
<<: *defaults |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe "RequestsDashboard", js: true do | |
let!(:req_processing_one) { create(:request, state: "processing", url: "processing-job-url-1") } | |
context "Processing requests" do | |
it "displays request details modal" do | |
find(:xpath, "//a[@href='#{job_request_admin_request_path(req_processing_one)}']").click | |
# this is passing on |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I'll illustrate the problem with an example. | |
I query the database for some aggregated results. Say there are 4 | |
aggregated counters I'm interested in and wanting to display them | |
in a 100% width div. Each of the counters should contribute to a | |
percentage of the full width. | |
For instance, my db query returns me somthing like this | |
| counter_1 | counter_2 | counter_3 | counter 4| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def percentagerize(collection, result=[], remainder=1) | |
collection = Array(collection) | |
return result if collection.count == 0 | |
denominator = collection.inject(:+) | |
percent = 0.0 | |
unless denominator == 0 | |
percent = (remainder * (collection[0] / denominator.to_f)).round(4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ChangeMachine | |
class IdiotEncountered < StandardError; end | |
AVAILABLE_UNITS = [10000, 5000, 2000, 1000, 500, 200, 100, 50, 20, 10, 5] | |
def self.show_me_the_money(dollar_in_cents) | |
raise IdiotEncountered, "You are an idiot, no such amount in AUS..." unless dollar_in_cents % 5 == 0 | |
dispense(dollar_in_cents) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"lastUpload":"2020-07-13T04:56:31.742Z","extensionVersion":"v3.4.3"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// utils/partial.js | |
export const partial = (func, ...args) => func.bind(null, ...args); | |
// actions/maths.js | |
export const addNumberOneAndNumberTwo = (first, second) => { | |
return { | |
type: 'SOMETHING THE REDUCER CAN CATCH', | |
first, | |
second, | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { isPlainObject } from 'lodash'; | |
import { batchActions as batchActionsDefault } from 'redux-batched-actions'; | |
const handleInnerAction = (action, getState) => { | |
if (typeof action === 'function') { | |
return new Promise(resolve => { | |
const innerDispatch = innerAction => resolve(handleInnerAction(innerAction, getState)); | |
action(innerDispatch, getState); | |
}); | |
} else if (isPlainObject(action)) { |
OlderNewer