Skip to content

Instantly share code, notes, and snippets.

View scottsbaldwin's full-sized avatar

Scott Baldwin scottsbaldwin

View GitHub Profile
@scottsbaldwin
scottsbaldwin / batch.py
Created March 26, 2020 22:14
Python - process list items in batches
batch_size = 3
l = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
while l:
s = l[:batch_size]
print(s)
l = l[batch_size:]

Converting an SVG to a PNG on Mac

Using ImageMagick:

convert picture.svg picture.png

Using qlmanage:

@scottsbaldwin
scottsbaldwin / pipedrive-file-uploader.js
Created June 6, 2017 14:51
Pipedrive File Uploader
var _ = require('lodash'),
fs = require('fs'),
FormData = require('form-data');
const PIPEDRIVE_API_TOKEN='REDACTED';
function addFileToDeal(filePath, dealId) {
return new Promise((resolve, reject) => {
if (_.isNil(filePath) || filePath === '') {
reject(new Error('filePath must be set.'));
@scottsbaldwin
scottsbaldwin / pipedrive-add-file-to-deal.js
Created April 27, 2017 22:16
Add file to deal in Pipedrive using node.js client
'use strict';
var Pipedrive = require('pipedrive');
var pipedrive = new Pipedrive.Client(process.env.PIPEDRIVE_API_TOKEN, { strictMode: true });
var params = {
"file_path": "/path/to/document.pdf",
"deal_id": 1
};
pipedrive.Files.add(params, (err, f) => {
@scottsbaldwin
scottsbaldwin / bulk-import-formatting.md
Last active April 6, 2017 15:45
Regex for Bulk Import Address and Phone Formatting

Regex for Bulk Import Address and Phone Formatting

Address Regex

^(.*), ?(.+), ?(UT),? ((\d{5})(-\d{4})?)
$1\t\t$2\t$3\t$5

Address 1 and 2 refinement

@scottsbaldwin
scottsbaldwin / avg-claim-time.json
Created March 31, 2017 16:19
Average claim time for phone-number-pool
{
"aggregations" : {
"avgSecondsBetweenClaims" : { "avg" : { "field" : "avgSecondsBetweenClaims" } }
}
}
@scottsbaldwin
scottsbaldwin / sanitize-geojson.md
Last active March 21, 2024 06:01
Cleanup GeoJSON for Import into Elasticsearch

Santize GeoJSON for Elasticsearch

Santize States

JSON=/Users/scott/src/geojson/us-states-20m.json
TARGET=data/prod-es/states.json
cat $JSON | jq -c '.features[] | { _index: "service-areas", _type: "state", _id: .properties.STATE , _source: { id: .properties.STATE, geoId: .properties.GEO_ID, serviceAreaType: "State", name: .properties.NAME, stateId: .properties.STATE, geometry: .geometry }}' > $TARGET
@scottsbaldwin
scottsbaldwin / self-signed-certificate.sh
Created October 3, 2016 14:46
Generate a self-signed certificate
#!/bin/bash
# Create a new self-signed cert that is good for a year
openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365
# Strip the passphrase from the cert
openssl rsa -in key.pem -out newkey.pem && mv newkey.pem key.pem
@scottsbaldwin
scottsbaldwin / sig_handler.sh
Created September 29, 2016 20:51
Execute a function on docker stop
#!/bin/sh
handler() {
echo "Caught SIGTERM signal"
exit $((15+128))
}
i=0;
trap 'handler' SIGTERM
while [ $i -lt 600 ]; do
@scottsbaldwin
scottsbaldwin / port-check.sh
Created September 13, 2016 14:59
Check if host:port is up
#!/bin/bash
# see https://securityreliks.wordpress.com/2010/08/20/devtcp-as-a-weapon/
echo "Waiting for ${HOST}:${PORT} to become available"
while :
do
(echo > /dev/tcp/${HOST}/${PORT}) >/dev/null 2>&1
available=$?
if [[ $available -eq 0 ]]; then
echo "Service on ${HOST}:${PORT}" is available