Skip to content

Instantly share code, notes, and snippets.

View revmischa's full-sized avatar
🇺🇦

Mischa Spiegelmock revmischa

🇺🇦
View GitHub Profile
"""Mass invite users from one channel to another."""
from slacker import Slacker
from pprint import pprint
slack = Slacker('xxxxx')
me = slack.auth.test().body
me_id = me['user_id']
@revmischa
revmischa / xml2json.xslt
Last active October 17, 2016 20:08
XSLT to convert XML TO JSON (lol)
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!--
Copyright (c) 2006,2008 Doeke Zanstra
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this
@revmischa
revmischa / myapp.py
Last active November 19, 2021 01:31
Deferred jobs with sqlalchemy/flask/apscheduler
# sample usage:
class MyFlaskApp(Flask):
...
def start_heartbeat(self):
"""Schedule periodic heartbeat updates."""
if hasattr(self, 'heartbeat_sched'):
raise Exception("Heartbeat already started")
sched = self.get_scheduler()
self.heartbeat_sched = sched
@revmischa
revmischa / open_iot_security_cert.md
Created June 13, 2017 02:42
Open IoT Security Certification Draft

Level I - Basic

Network

Software/Firmware

  • No default username/password
    • Devices must not ship with a well-known username and/or password
      • Unless the password must be changed on first use No backdoor passwords in firmware. This can be dumped and reversed and published.
@revmischa
revmischa / logplex_syslog_lambda.py
Last active November 20, 2018 10:25
Heroku logplex syslog handler lambda
"""Sample handler for parsing Heroku logplex drain events (https://devcenter.heroku.com/articles/log-drains#https-drains).
Expects messages to be framed with the syslog TCP octet counting method (https://tools.ietf.org/html/rfc6587#section-3.4.1).
This is designed to be run as a Python3.6 lambda.
"""
import json
import boto3
import logging
import iso8601
@revmischa
revmischa / eurobash_prompt.sh
Last active October 27, 2017 20:22
European Bash Prompt ($PS1)
if [[ `whoami` == "root" ]]; then
ISROOT=1
fi
# Git branch in prompt.
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(❲.*\)/ ❲\1❳/'
}
# git status
parse_git_dirty() {
@revmischa
revmischa / handler.py
Created January 15, 2019 08:03
Twilio call handler lambda
from twilio.twiml.voice_response import VoiceResponse, Dial
from twilio.rest import Client
from urllib.parse import parse_qsl
import requests
import json
from pprint import pprint
import boto3
session = boto3.session.Session()
@revmischa
revmischa / sdl_version_check.m4
Last active February 9, 2019 16:12
Autoconf m4 to check if minimum SDL library version exists
# SDL
AC_ARG_ENABLE([sdl], AS_HELP_STRING([--enable-sdl], [Build SDL2 application]), [], [enable_sdl=check])
AS_IF([test "$enable_sdl" != "no"], [
m4_include([m4/sdl2.m4])
SDL_VERSION="2.0.5"
AS_IF([test "$TRAVIS"], [SDL_VERSION=2.0.2]) # travis has old SDL, we don't care
AS_IF([test "$EMSCRIPTEN"], [SDL_VERSION=2.0.0]) # emscripten has old SDL, we don't care
# Check for libSDL >= $SDL_VERSION
found_sdl=no
@revmischa
revmischa / response_unwrap.kt
Created March 11, 2019 18:34
Always unwrap a JSON response key using Retrofit/Moshi/Kotlin
// for parsing "data" out of every response object
// https://stackoverflow.com/questions/23070298/get-nested-json-object-with-gson-using-retrofit/40691739#40691739
class ItemTypeAdapterFactory : TypeAdapterFactory {
override fun <T> create(gson: Gson, type: TypeToken<T>): TypeAdapter<T> {
val delegate = gson.getDelegateAdapter(this, type)
val elementAdapter = gson.getAdapter(JsonElement::class.java)
return object : TypeAdapter<T>() {
override fun write(out: JsonWriter, value: T) {
@revmischa
revmischa / serverless.yml
Last active April 11, 2019 10:21
Serverless CloudFormation to provide private RDS and lambda networking with internet access in VPC.
plugins:
- serverless-pseudo-parameters
provider:
name: aws
runtime: python3.7
stage: ${opt:stage, 'dev'}
environment:
SQLALCHEMY_DATABASE_URI: # DB DSN