Skip to content

Instantly share code, notes, and snippets.

View jakerobers's full-sized avatar
🏠
Working from home

Jake Robers jakerobers

🏠
Working from home
View GitHub Profile
#!/bin/bash
# Generates a pdf invoice from a text file.
#
# Usage:
# ./generate_invoice invoice_0000.txt
BASE=$(basename -s .txt $@)
echo "${BASE}"
enscript -B $@ -o "${BASE}".ps
ps2pdf "${BASE}".ps out/"${BASE}".pdf
From:
Company Name
Address 1
Address 2
Phone number
Email
Sold To:
Company Name
Address 1
import _ from 'lodash';
export const getHighestRank = (ranks) => _.maxBy(ranks, 'rank')
// export const getSomeValue...
import _ from 'lodash';
export const getHighestRank = (ranks) => {
return _.reduce(ranks, (acc, e) => {
if (e.rank > acc.rank) {
return e;
}
return acc;
}, ranks[0]);
}
import _ from 'lodash';
export const getSomeValue = () => {
// some code ...
const highestRank = _.reduce(ranks, (acc, e) => {
if (e.rank > acc.rank) {
return e;
}
return acc;
# memento_pull.py
import boto3, os, sys
has_messages = True
sqs = boto3.resource('sqs', region_name='us-east-1')
queue_url = os.environ['AWS_SQS_URL']
while has_messages:
response = sqs.meta.client.receive_message(QueueUrl=queue_url, MaxNumberOfMessages=10)
@application.route('/sqs', methods=['POST'])
@auth.validate_authenticated(token=application.config['AUTHENTICATION_TOKEN'])
def sqs_create():
text = flask.request.get_json()['text']
sqs.meta.client.send_message(
QueueUrl=application.config['AWS_SQS_URL'],
MessageBody=(text)
)
return flask.Response(text, mimetype='text/plain')
# tests/test_myresources.py
@unittest.mock.patch('lib.myresources.myreqs')
def test_get_resources_calls_one(self, myreqs):
myresources.get_resources()
myreqs.fetch_thing_1.assert_called_once()
@unittest.mock.patch('lib.myresources.myreqs')
def test_get_resources_calls_two(self, myreqs):
myresources.get_resources()
# tests/test_myreqs.py
# ... test_fetch_thing_* methods
@unittest.mock.patch.object(myreqs, 'fetch_thing_1')
@unittest.mock.patch.object(myreqs, 'fetch_thing_2')
@unittest.mock.patch.object(myreqs, 'fetch_thing_3')
def test_get_resources_calls_one(self, thing_3, thing2, thing1):
myreqs.get_resources()
thing1.assert_called_once()
# tests/test_myreqs.py
# ... test_fetch_thing_* methods
@unittest.mock.patch.object(myreqs, 'fetch_thing_1')
@unittest.mock.patch.object(myreqs, 'fetch_thing_2')
@unittest.mock.patch.object(myreqs, 'fetch_thing_3')
def test_get_resources(self, thing_3, thing2, thing1):
myreqs.get_resources()
thing1.assert_called_once()
thing2.assert_called_once()