Skip to content

Instantly share code, notes, and snippets.

@teebu
teebu / imagemagick.bash
Last active July 11, 2020 16:21 — forked from bensie/imagemagick.bash
ImageMagick Static Binaries for AWS Lambda ImageMagick-6.9.10-8 for AWS Lambda
#!/usr/bin/env bash
# Must be run on an Amazon Linux AMI that matches AWS Lambda's runtime
# As of Nov 23, 2015, this is Amazon Linux AMI 2014.09.2 x86_64 (ami-0c682c64)
#
# Lambda includes ImageMagick 6.7.8-9 preinstalled, so you need to prepend PATH
# with the folder containing these binaries in your Lambda function to ensure
# these newer binaries are used.
#
# imagemagick binary will be in /var/task/imagemagick/bin/convert
@teebu
teebu / amazon_linux_install_varnish4.1.10.sh
Last active May 23, 2020 19:18 — forked from tankhuu/amazon_linux_install_varnish4.1.10.sh
Amazon Linux Install Varnish 4.1.10
# varnish 4.1
sudo yum -y install autoconf automake jemalloc-devel libedit-devel libtool ncurses-devel pcre-devel pkgconfig python-docutils python-sphinx graphviz
curl -s https://packagecloud.io/install/repositories/varnishcache/varnish41/script.rpm.sh | sudo bash
wget --content-disposition https://packagecloud.io/varnishcache/varnish41/packages/el/6/varnish-4.1.10-1.el6.x86_64.rpm/download.rpm
sudo rpm -Uvh varnish-4.1.10-1.el6.x86_64.rpm
/usr/sbin/varnishd -V
# varnish 4
sudo yum -y install autoconf automake jemalloc-devel libedit-devel libtool ncurses-devel pcre-devel pkgconfig python-docutils python-sphinx graphviz
@teebu
teebu / Python column row
Last active March 10, 2020 01:42
Print columns and rows of array elements with padding
def col_print(title, array, term_width=150, pad_size=1):
indent = " " * 4
pad = " " * pad_size
title += "\n"
if not array:
return title + indent + "<None>"
array = list(map(str, array)) # make every element a string
max_item_width = max(map(len, array))
@teebu
teebu / vigenere_cipher.py
Created March 8, 2020 05:28
Python class for vigenere cipher
"""Vigenere cipher"""
import string
from collections import defaultdict
from pprint import pprint
class Vigenere():
"""Vigenere class"""
def __init__(self, key, message=''):
self._MATRIX = self._build_matrix()
@teebu
teebu / Output Android Icons.jsx
Created March 2, 2019 22:31 — forked from Gamezpedia/Output Android Icons.jsx
Photoshop script to output Android icons (with XXXHDPI, XXHDPI, XHDPI, HDPI, MDPI support)
// Output Android Icons.jsx
// 2012 Todd Linkner
// License: none (public domain)
// v1.0 - base file by Todd Linkner
// v1.1 - added support for XXHDPI, XXXHDPI and added PNG to the file selector
//
// This script is for Photoshop CS6. It outputs Android icons of the
// following sizes from a source PSD at least 512px x 512px
//
// store:
@teebu
teebu / logstash.conf
Last active February 6, 2019 10:08 — forked from maxkandler/logstash.conf
Grok filter for Cloudfront Logs to be used with Logstash & ElasticSearch
filter {
grok {
match => [
"message", "%{YEAR:year}-%{MONTHNUM:month}-%{MONTHDAY:day}[\t]%{TIME:time}[\t](?<x_edge_location>\b[\w\-]+\b)[\t](?:%{NUMBER:sc_bytes}|-)[\t]%{IPORHOST:clientip}[\t]%{WORD:cs_method}[\t]%{HOSTNAME:cs_host}[\t]%{NOTSPACE:cs_uri_stem}[\t]%{NUMBER:sc_status}[\t]%{GREEDYDATA:referrer}[\t]%{GREEDYDATA:agent}[\t]%{GREEDYDATA:cs_uri_query}[\t]%{GREEDYDATA:cookies}[\t]%{WORD:x_edge_result_type}[\t]%{NOTSPACE:x_edge_request_id}[\t]%{HOSTNAME:x_host_header}[\t]%{GREEDYDATA:cs_protocol}[\t]%{INT:cs_bytes}[\t]%{GREEDYDATA:time_taken}[\t]%{GREEDYDATA:x_forwarded_for}[\t]%{GREEDYDATA:ssl_protocol}[\t]%{GREEDYDATA:ssl_cipher}[\t]%{GREEDYDATA:x_edge_response_result_type}[\t]%{GREEDYDATA:cs_protocol_version}"
]
}
geoip {
source => "c_ip"
}
mutate {
@teebu
teebu / removeblankpages.sh
Created August 2, 2018 02:41
Remove blank pages from PDF
#!/bin/bash
IN="$1"
OUT="$2"
PAGES=$(pdfinfo $IN | grep ^Pages: | tr -dc '0-9')
non_blank() {
for i in $(seq 1 $PAGES)
do
# more color spectrum
#convert -density 46 "$IN[$((i-1))]" -define histogram:unique-colors=true -format %c histogram:info:- | wc -l
if [ $(convert -density 16 "$IN[$((i-1))]" +dither -colors 8 -depth 4 -define histogram:unique-colors=true -format %c histogram:info:- | wc -l) -ne 1 ]
@teebu
teebu / delay.js
Created July 6, 2018 05:40 — forked from daliborgogic/delay.js
Node.js Async/Await delay
'use strict'
const timeout = ms => new Promise(res => setTimeout(res, ms))
function convinceMe (convince) {
let unixTime = Math.round(+new Date() / 1000)
console.log(`Delay ${convince} at ${unixTime}`)
}
async function delay () {
@teebu
teebu / remove_pdf_password.sh
Created January 12, 2018 21:52 — forked from pstaender/remove_pdf_password.sh
Remove password from protected PDF file with GhostScript
gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=unencrypted.pdf -c .setpdfwrite -f encrypted.pdf
@teebu
teebu / install_python_36_amazon_linux.sh
Created December 22, 2017 01:04 — forked from niranjv/install_python_36_amazon_linux.sh
Install Python 3.6 in Amazon Linux
# A virtualenv running Python3.6 on Amazon Linux/EC2 (approximately) simulates the Python 3.6 Docker container used by Lambda
# and can be used for developing/testing Python 3.6 Lambda functions
# This script installs Python 3.6 on an EC2 instance running Amazon Linux and creates a virtualenv running this version of Python
# This is required because Amazon Linux does not come with Python 3.6 pre-installed
# and several packages available in Amazon Linux are not available in the Lambda Python 3.6 runtime
# The script has been tested successfully on a t2.micro EC2 instance (Root device type: ebs; Virtualization type: hvm)
# running Amazon Linux AMI 2017.03.0 (HVM), SSD Volume Type - ami-c58c1dd3
# and was developed with the help of AWS Support