Skip to content

Instantly share code, notes, and snippets.

View japsu's full-sized avatar

Santtu Pajukanta japsu

View GitHub Profile
@japsu
japsu / aws-config
Last active January 18, 2018 09:22
Get a AWS CLI session with STS role and MFA: `eval $(awssume-role prod 666666)`
[default]
region = eu-central-1
[profile prod]
role_arn = arn:aws:iam::…
source_profile = default
mfa_serial = arn:aws:iam::…
@japsu
japsu / aws-mfa.py
Last active December 15, 2017 19:00
Authenticate to AWS using MFA and output tokens in a format suitable for `eval $(aws-mfa 666666)`
#!/usr/bin/env python3
import os
import configparser
import sys
import boto3
def main(token_code, serial_number):
FROM python:3.6
RUN pip install django-environ==0.4.1
COPY test.py /usr/src/app/test.py
CMD ["python", "/usr/src/app/test.py"]
@japsu
japsu / README.md
Last active January 2, 2018 17:56
Type-safe Redux reducers in TypeScript using Immutable.js and typed-immutable-record

Type-safe Redux reducers in TypeScript using Immutable.js and typed-immutable-record

Copyright (C) 2017 Leonidas Oy Ltd
Written by <[email protected]>
Licensed under the MIT license

We attempt to harness the friendly API of Immutable.js to build Redux reducers while trying to preserve as much type safety as possible.

State branches are TypedRecords. A combineReducers that outputs TypedRecords is provided.

@japsu
japsu / index.js
Created May 24, 2016 09:35
schemaByExample – generate JSON schema from example object
import _ from 'lodash';
export default function schemaByExample(example) {
if (_.isArray(example)) {
return {
type: 'array',
items: schemaByExample(example[0])
};
} else if (_.isPlainObject(example)) {
- name: tap some homebrew repositories
homebrew_tap: tap={{ item }}
with_items:
- caskroom/cask
- caskroom/versions
- homebrew/dupes
- homebrew/versions
- name: install software via brew
homebrew: name={{ item }}
@japsu
japsu / DRINK.md
Last active February 19, 2016 12:06
Shannara-juomapeli

The Shannara Chronicles (MTV) -juomapeli

Juodaan, kun

  1. Elfsplaining
  2. Se on kohtalosi
  3. The Dagda Mor
  4. Amberle ja Eretria piikittelevät toisiaan
  5. Amberle tai Eretria on mustasukkainen Wilistä
  6. Muodonmuuttajan silmät välähtävät
@japsu
japsu / popover.js
Last active August 27, 2015 20:21
Show img[alt] in a Bootstrap 3 popover without any extra markup (doesn't break floats etc)
(function($) {
$('img[alt]').each(function() {
var $this = $(this);
$this
.attr('data-content', $this.attr('alt'))
.hover(function() {
$(this).popover('show');
}, function() {
$(this).popover('hide');
});
from straightened import TCPLineProtocol
protocol = TCPLineProtocol()
@protocol.on_line_received
def echo_protocol_line_received(transport, data):
transport.send_line(data)
protocol.listen(9000)
@japsu
japsu / slots_repr.py
Created February 4, 2015 08:34
__repr__ for classes that use __slots__
def slots_repr(self):
"""
Provides a readable, namedtuple-like __repr__ for classes that use __slots__.
Usage:
>>> class A(object):
... __slots__ = ['b']
... __repr__ = slots_repr
...