Skip to content

Instantly share code, notes, and snippets.

Avatar
🏍️

Steve Lacy stevelacy

🏍️
View GitHub Profile
@stevelacy
stevelacy / parse-env-to-map.go
Created Apr 2, 2020
Parse ENV to a string map in go
View parse-env-to-map.go
func envToMap() map[string]string {
env := os.Environ()
mapped := map[string]string{}
for _, v := range env {
s := strings.Split(v, "=")
mapped[s[0]] = s[1]
}
return mapped
}
@stevelacy
stevelacy / find-replace-recursive.md
Created Mar 25, 2020
Find and replace recursive
View find-replace-recursive.md

Find and replace recursive

find . -name "*.ex" -exec sed -i '' -e "s/project/Project/g" {} +

Find and replace TypeScript imports

replace 'models with '../../models

find . -name "*.ts*" -exec sed -i '' -e "s/'models/'\.\.\/\.\.\/models/g" {} +

@stevelacy
stevelacy / func-to-arrow-func.js
Created Apr 24, 2019
method to arrow function code mod
View func-to-arrow-func.js
module.exports = function transform(file, api) {
const j = api.jscodeshift
function withComments(to, from) {
to.comments = from.comments
return to
}
function createArrowProperty(prop) {
return withComments(j.classProperty(
@stevelacy
stevelacy / file.go
Last active Mar 14, 2019
Open a 99M (1,000,000 line) text file in golang and store as []Rows
View file.go
package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
"time"
)
@stevelacy
stevelacy / docker-compose-migration.yaml
Created Oct 11, 2018
Docker compose file with migrations and nginx + nginx-proxy
View docker-compose-migration.yaml
version: "3"
services:
api:
image: "stevelacy/imagehere"
command: ["/app/init"]
ports:
- 80
depends_on:
- migration
@stevelacy
stevelacy / delete-slow-pg-queries.md
Created Apr 17, 2018
Delete slow or long running queries on postgres
View delete-slow-pg-queries.md
SELECT pg_cancel_backend(pid),
  pid,
  now() - pg_stat_activity.query_start AS duration,
  query,
  state
FROM pg_stat_activity WHERE (now() - pg_stat_activity.query_start) > interval '5 minutes';
@stevelacy
stevelacy / tile38-intersect.sh
Created Mar 23, 2018
Check if time of results are cached
View tile38-intersect.sh
#!/bin/bash
random1=$(((RANDOM % 10) + 1))
random2=$(((RANDOM % 10) + 1))
tile38-cli 'INTERSECTS boundaries IDS OBJECT { "type": "Polygon", "coordinates": [ [ [ -74.0460'${random1}'53381, 40.750743837'${random1}'4 ], [ -74.05118'${random2}'1453, 40.743'${random1}'9884844 ], [ -74.0452'${random2}'9195, 40.7409'${random1}'41359 ], [ -74.04'${random1}'1958618, 40.7486712'${random1}'115 ], [ -74.0460'${random1}'53381, 40.750743837'${random1}'4 ] ] ] }'
@stevelacy
stevelacy / glitch.md
Last active Jan 15, 2020
͓͉̬͙͆ͨͣͥ̇͊ͫͣ̿̿̑̚̚̕@̶̡̣͖͙̺͈̤̹̹̦͆͐ͯͤ̿̂͑̈́͂̆̏̔̌̚̕̕͟$̵̶ͩ̾̌̅̎͋̊͗ͪ́
View glitch.md

K̷̢̦͔̣̲͕̟̜̬̘͎̟̍̔ͧͦͩ͊ͩͪ̈̃̕͡ͅͅ@̴̨͔̠͍̣̮̙̲̝̥̋ͫ͑̔̉͆̆̃̄͂̑̕n̵̳̗͖̥̹͉̜͕̻͓̠̜͋̈̅̄͐͐ͮ̑̿̀ ̨̛̱͈̣͚̫̳̦̭̭͇̲͓͔̙͆͗̂̅ͫ̓̇̄ͤ͆̄͛ͮ͐͘͜͞ͅͅv̶̸̢̳̳̪͔͈̬̆̈ͮ̌̀̓̓̈́ͥ̏ͫ͒͗̚ͅ1̴̶͇̯̼̲̩̘͔͖͔͗̑̓̃͑̐́͆̊̉͆́ͧ̃͢3̶̨̡̲̘̖̝̥̣͖̤̰̖̗̭̎̓̒̆͋ͯ̋̆͠ͅw̶̨̥̤͕̤̩̦ͧͨ͛̽̄́͆ͥͤ͠ ̵̴̲͍̙̪̞̠͎̩ͦ͌͊͐́͌̉̎̄̓͝ŗ̸̡͚̘͚͈ͩ͆̆ͦ͒̍3̹̠͕͈͙͎̘̠ͮ̾̿͛ͤ͗͒ͫ́͞ͅ5̶̥͔̞̭̤̜̥̺̻̲̭̭͉̘̬̂ͥ̿ͦͥ͛̽͋͢u̸̧̳͈͈̪̣̠͈̍́̔͑̒ͥ͊̽͆͊̓̈̊̑ͧ̓̊̋̀͟͢|̨̥͈̙͇͌ͨ̇̉̀̒̆̊ͯͬͫ̄̌ͣ̽̂̐ͪ̕͞7̨̘̖̮̥̪̈́̾̒͑̄͋ͨ̂͒̀ͣ͆̊̓̚͘͝z̸̨̝̯͚̻̈͗ͯ͒͗ͮ̓̊̇̍ ̧̧͖͉̯̖̬̫͈̦͕̖̱̰̩͚̦̦̖̔̆ͯ̾ͯ̚͜͡d̢͙̗̳̤͎͔̹̱͍͔̺͎̒̿̎̉̍ͦͤͧͨ͠ͅ0̵̷͖̯͓͎̝̪̹̫̮͈̮̼̩̇ͪͣ͛̇̓͛͗ͣ͐̍̒́͂͗̏͂̕͘͜,̸̴͎̬̮̆̏ͮ̐ͮ̈ͤͫ̓̽͑ͪ̅͋͌́̕ ̸̜͓͙͇̥͉̗͉͒̂̊̓ͩ̈́ͦ̓͋ͭ͊̂̓̆́͢͞͝͠ͅW̢̨ͭ̒̔̋͏̯̤͎̣̜͇̯ͅh̷̰͍̰͉̘̯̳̥̥̼͔͔̤͈̰̩͆̓̃̈́̃̕1͎̭̗͉̗͕̥̯̰̭̼̘̃ͯ̇ͣ́͜͡Ç̛̥̻̲̺̝̹̮̗̙̼̱̬͒͆̆̚͟͞h̿ͬ̋̍̄̇̈́ͬ͑͋̐ͬ̌̅͏̱̝̗̫̫̭̥̩̤̮̝̭͙̯̞̥͜ ̸̡̬̪̗̗̣͖̯͖̣̹̹̣̰̋ͯ̏ͯͯͣ̇ͤ͐̚ͅ|̡̠̩̣̠̤̦̼͖̬̗̫̻̹̫͓ͤ̂ͬ͆͋ͯ̍̃̀͝2ͣͦ̂ͫ̿͛̓͊̍ͭ̽̆̽̿͝͡҉̸̵̤̻͇̹͉͚͓͚̙̱͚̰̬̲1̶̷̷̖͍͖͓̩̠̦͚͕͐̎̎̌̓ͪ̆̅̔̀̆͌͊ͥͩ̈̈̿ͯg̱̰̰̫͓̩̘͙̝͊̒̍ͮ̿ͨ̃ͧ͆̾̃̈͋ͩ̄̀̚͡h̡̘̺͖̤͍̰̟̠̮͖̼̐̿̃ͮ̂ͮ̽̎̿ͪ̓́͜͟7̝͙̦̤̘̬͎̖̥̳̤̱̤̹̰͕̫̪͓ͯͩͪ̒̈̍̑͂ͥ̂ͥ͘͠ ͆͗̏̍̈́̃ͫ̔ͥ̃ͦͣ̚҉̷̝̩̱͔̟̜̤̟̺̳̩̹̝̖̯̮͎͖͜(̶̸̬̼͓̗͉̥̻͔͔̝̮͕̗͖͔̣͊̎̏ͣͅ4̴̿͒̈́͊̏̅͆ͨ͏̷̝̞̺̫̯͈̖͙̖̥(̵̺͈̲̯͔̬̤̰ͥ̆̓ͮ͆͋͋̌̽͘͟͜͡]̶̛̝̥̤̮̳͔̹͉͖͚͎̬̺̘̔̏̍͌-̶̢̟͔̣̞͓̤ͮͪͫ̊͛̏̓ͨ̈́͊̋̉̂̈ͦ͊̚̕͢[̛̼̘̺̗̤̦ͩ̐̅ͣ̓̈́ͮ͑̊͡

@stevelacy
stevelacy / check-database-toast-tables.md
Created Feb 27, 2018
look for corrupt postgres toast tables (with uuid)
View check-database-toast-tables.md
You can’t perform that action at this time.