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
const fs = require('fs') | |
module.exports = { | |
writeTerraform, | |
generateMain, | |
} | |
// Templates are just terraform (.tf files) with the following kinds of interpolations: | |
// 1. Variables embedded in a string: "terraform-states-<id>" | |
// 2. Variables occupying an entire string: "<apiId>". |
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
function isObject (value) { | |
return value != null && typeof value === 'object' && value.constructor === Object | |
} | |
////////////////////////////////////////// | |
// GENERATOR | |
////////////////////////////////////////// | |
function * traverseObj (value, path = []) { |
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
#!/bin/bash | |
uname -a | |
if test -f "/etc/os-release"; then | |
cat /etc/os-release | |
fi | |
if command -v lsb_release; then | |
lsb_release -a | |
fi | |
cat /proc/version |
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
-- Order by one indexed column (FAST) | |
newsdesk_production=# explain analyze select * from pressreleases order by published_at DESC limit 100; | |
QUERY PLAN | |
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
Limit (cost=0.00..249.91 rows=100 width=1207) (actual time=26.070..716.453 rows=100 loops=1) | |
-> Index Scan Backward using pressreleases_published_at_index on pressreleases (cost=0.00..964766.62 rows=386042 width=1207) (actual time=26.067..716.343 rows=100 loops=1) | |
Total runtime: 716.709 ms | |
(3 rows) | |
- Order by two separately indexed columns (SLOW) |
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 counts_from_dice(dice) | |
dice.inject({}) do |hash, value| | |
hash[value] ||= 0 | |
hash[value] += 1 | |
hash | |
end | |
end | |
def score(dice) | |
counts_from_dice(dice).inject(0) do |sum, (number, count)| |
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
class ImportLegacyDevices < ActiveRecord::Migration | |
def self.up | |
return unless Rails.env.production? | |
legacy_devices.each do |device_id, issue| | |
if device = Device.find_by_hardware_id(device_id) | |
unless InclusiveIssue.exists?(:issue_id => issue.id, :device_id => device.id) | |
InclusiveIssue.create!( | |
:issue => issue, | |
:device => device, |
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
# 0. Make sure you have Ruby 1.9.3 installed, and optionally RVM and PostgreSQL | |
# 0.2 If you are on the Mac, make sure you have a c compiler by installing XCode Command Line Tools or gcc4.2 with homebrew | |
# https://github.com/mxcl/homebrew/wiki/Custom-GCC-and-cross-compilers | |
# 0.5 Make sure you have bundler version ~> 1.2 as Rails depends on it | |
gem install bundler | |
# 1. Get edge Rails source (master branch) | |
git clone https://github.com/rails/rails.git |
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
// The use case is that you are developing a web app locally that makes Ajax requests to some external | |
// API that doesn't have sufficiently permissive CORS headers so your requests fail. The solution is to point the app | |
// to this local proxy which will allow CORS. | |
const http = require('http') | |
const axios = require('axios') | |
const HOSTNAME = '127.0.0.1' | |
const PROXY_BASE_URL = process.env.PROXY_BASE_URL; | |
const PORT = process.env.PORT || 9999 |
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 crypto from 'crypto'; | |
export function basicAuthMiddleware({ name, pass }: any): Function { | |
const auth = `Basic ${Buffer.from([name, pass].join(':')).toString( | |
'base64' | |
)}`; | |
return async (ctx: any, next: any): Promise<any> => { | |
const header = ctx.request.get('Authorization'); | |
const headerMatches = | |
header && |
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
/* eslint-disable no-plusplus */ | |
import crypto from 'crypto'; | |
function parse(header: string | null): string | null { | |
const match = (header || '').match(/^Basic (\S{3,300})$/); | |
return match && Buffer.from(match[1], 'base64').toString(); | |
} | |
function isEqual(s1: string | null, s2: string | null): boolean { | |
return ( |