Skip to content

Instantly share code, notes, and snippets.

View shaisachs's full-sized avatar

Shai Sachs shaisachs

View GitHub Profile
# add date: field to every post in a directory, using the last git commit date for that post
for f in * ; do
echo $f
d=`git log -n 1 --date=format:'%Y-%m-%d %H:%M:%S' $f | grep Date | cut -c 9-`
sed -i -e '/^title:/a\
date: "$d"
' "$f"
done
@shaisachs
shaisachs / add-and-swap.sh
Last active October 10, 2022 15:02
Adding and swapping lines in sed
# I had a bunch of files across three different directories
# I wanted to combine them into one big directory with a "format" marker to indicate what type of file they were
# Here's how I did it in sed
mkdir tmp
cp gitrepos/* tmp/
cd tmp
for f in *.md ; do sed -i '' '3 i\
format: gitrepo
@shaisachs
shaisachs / jekyll-serve.sh
Created October 4, 2022 14:24
jekyll serve
# serve up a jekyll site, "no questions asked"
docker run -p 4000:4000 --rm --volume="$PWD:/srv/jekyll:Z" -it jekyll/jekyll:3.8 jekyll serve
@shaisachs
shaisachs / VAN Demo Postman collection.json
Last active October 19, 2020 18:12
VAN Demo Postman collection
{
"info": {
"_postman_id": "3fea52d3-a544-418a-8c8c-933255e13371",
"name": "VAN demo",
"description": "Indicates how to run some very common API requests in VAN. More complete documentation at https://developers.ngpvan.com/.\r\n\r\nFor security purposes, the fully API key has been redacted, so none of these API calls will work as-is. Before using this collection, please find/replace \"****c70b\" with your actual API key.\r\n\r\nAlso note that some of these API calls have dependencies on earlier API calls - for example, the activist code and survey question in \"Apply canvass responses\" are drawn from the response in \"Get activist codes\" and \"Get survey questions\", respectively. The responses in the \"Get activist codes\" and \"Get survey questions\" API calls are in turn dependent on configuration in the VAN user interface - so different API keys will have different responses. These dependencies are noted in each API call's description.",
"schema": "https://schema.getpostman.com/json/co
@shaisachs
shaisachs / rows-to-csv.sql
Last active May 1, 2018 18:53
TSQL rows to csv
-- from https://stackoverflow.com/questions/887628/convert-multiple-rows-into-one-with-comma-as-separator
select *
into #tmpdata
from things
where thingid >= 100 and thingid <= 200
declare @answer varchar(1000) = ''
select @answer = @answer + id + ', ' from #tmpdata
@shaisachs
shaisachs / preFillCustomField.js
Last active September 18, 2017 16:58
ActionTag - prefill a custom field input
// see https://developers.everyaction.com/action-tag#callbacks-alterfill
// assumes your Custom Field ID is 1234
function populateCustomField(args) {
if (args.fill_source !== 'FastAction') {
return args;
}
if (!args.fill_dict['CustomField_1234']) {
args.fill_dict['CustomField_1234'] = preFilledCustomFieldValue();
}
@shaisachs
shaisachs / savedlists.json
Created September 15, 2017 19:12
Sample response from GET /savedLists
{
"items": [
{
"savedListId": 12345,
"name": "Sample saved list",
"description": "",
"listCount": 25,
"doorCount": 13
}
],
@shaisachs
shaisachs / find-meetup-groups.sh
Created July 15, 2016 20:17
Find meetup groups of interest in a local area
# make sure to clone https://github.com/shaisachs/python-api-client
apikey=asdf # get key from https://secure.meetup.com/meetup_api/key/
for z in 20005 02143 ; do
for t in ".net" "c#" azure ; do
echo "$t within 5 miles of $z"
python python-api-client/findGroups.py --apikey=$apikey --radius=5 --zip=$z --text="$t"
done
@shaisachs
shaisachs / coffescript.c
Created June 21, 2016 18:25
Coffee algorithm
function getCoffee() {
if (asleep) {
return 0;
}
else {
return getCoffee() + 1;
}
}
@shaisachs
shaisachs / urlTokenEncode.sql
Last active May 26, 2016 14:33
UrlTokenEncode a GUID
drop function dbo.convertPaddingToCount;
go
create function dbo.convertPaddingToCount(@input varchar(1000))
returns varchar(1000)
as
begin
if (LEN(@input) < 1)
return '';