Skip to content

Instantly share code, notes, and snippets.

View iainelder's full-sized avatar

Iain Samuel McLean Elder iainelder

View GitHub Profile
@iainelder
iainelder / intercom-delete-old-users.js
Created October 12, 2018 15:56 — forked from zthomas/intercom-delete-old-users.js
Script to delete and clear old users from intercom. Useful for lowering the monthly bill
// License: MIT, feel free to use it!
const Intercom = require('intercom-client');
const appId = 'APP_ID'
const apiKey = 'APP_KEY'
const client = new Intercom.Client(appId, apiKey);
const async = require('async-q')
//REF: https://developers.intercom.com/reference#iterating-over-all-users
//WARNING: you can only have one scroll working at once. you need to wait for that scroll to clear to try again
@iainelder
iainelder / example.json
Created November 26, 2016 14:48
example.json for packer issue
{
"variables": {
"aws_access_key": "",
"aws_secret_keu": ""
},
"builders": [{
"type": "amazon-ebs",
"access_key": "{{user `aws_access_key`}}",
"secret_key": "{{user `aws_secret_key`}}",
"region": "us-east-1",
@iainelder
iainelder / repro_for_synonym_chaining_is_not_allowed.sql
Last active August 29, 2015 14:10
Repro for "Synonym chaining is not allowed".
CREATE SYNONYM first_link FOR second_link;
CREATE SYNONYM second_link FOR third_link;
CREATE TABLE third_link (a INT);
-- Msg 470, Level 16, State 1, Line 7
-- The synonym "first_link" referenced synonym "second_link". Synonym chaining is not allowed.
SELECT *
FROM first_link;
# T-SQL doesn't support the INTERSECT ALL operator.
# This gets you close.
# It only returns just one copy of each duplicate.
# GROUP BY * is not valid syntax so you have to write all the column names out.
SELECT *
FROM (
SELECT *
FROM #HasDupes
UNION ALL
SELECT DISTINCT *
@iainelder
iainelder / Get-ADGroupsForUser.ps1
Last active December 25, 2015 05:09
Output as a table all the active directory groups I am a member of. Is there a more elegant way to turn a list into a column?
@('iain', 'admin_iain') |
% {
$id = $_
(Get-ADPrincipalGroupMembership -Identity $id | Select -ExpandProperty name) |
% {
@{ $id = $_ }
}
}
@iainelder
iainelder / archive-requests-cache.py
Created October 6, 2013 20:09
Write requests cache to files.
import requests
import requests_cache
from urlparse import urlparse
from os.path import basename
def dump_cache():
"""
Writes all the responses in the cache to files.
The filename is the basename of the URL.
@iainelder
iainelder / dump-requests-cache.py
Created October 6, 2013 19:00
requests_cache is a library that caches responses returned by the requests library. This gist shows you how to dump the cache content to the shell. You can take this as a base for saving resposes to file for archiving. Using a cache allows you to implement the arching logic seperately from the fetching logic.
import requests
import requests_cache
from urlparse import urlparse
from os.path import basename
from pprint import pprint
# By default requests uses urlib3
# <class 'requests.packages.urllib3.response.HTTPResponse'>
resp = requests.get('http://httpbin.org/user-agent')
print type(resp.raw)