Skip to content

Instantly share code, notes, and snippets.

View m-x-k's full-sized avatar

Martin Kelly m-x-k

View GitHub Profile
@m-x-k
m-x-k / installCertificate.sh
Created September 1, 2017 07:31
Install self signed certificate on debian machine
#!/bin/bash
if [ $# -eq 0 ]
then
echo "./installCertificate.sh <HOSTNAME> <PORT>"
exit
fi
HOSTNAME=$1
PORT=$2
@m-x-k
m-x-k / StreamControllerExample.java
Created August 16, 2017 20:53
Spring MVC return output stream as response using lambda
import org.apache.commons.io.IOUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
@Controller
public class StreamControllerExample {
@m-x-k
m-x-k / findFolderLike.go
Created July 30, 2017 13:23
Golang script to find folders with matching string
package main
import (
"os"
"log"
"path/filepath"
"strings"
)
func findFolderLike(dir string, match string) {
@m-x-k
m-x-k / recursiveFileInfo.go
Created July 29, 2017 15:27
Output file size and check if a duplicate exists for all files in a specific directory
package main
import (
"os"
"fmt"
"log"
"crypto/sha512"
"io/ioutil"
"path/filepath"
)
@m-x-k
m-x-k / active_directory_users.py
Created July 18, 2017 12:12
Python ldap3 active directory add and search for users
import ssl
from flask import json
from ldap3 import Server, \
Connection, \
SUBTREE, \
ALL_ATTRIBUTES, \
Tls, MODIFY_REPLACE
OBJECT_CLASS = ['top', 'person', 'organizationalPerson', 'user']
@m-x-k
m-x-k / version.py
Last active April 8, 2018 02:13
Python version support
import os
from pathlib import Path
current_dir = os.path.dirname(__file__)
version_file_full_path = os.path.join(current_dir, "VERSION.txt")
"""
Create and obtain version information based on environment variables:
* APP_MAJOR_VERSION
@m-x-k
m-x-k / after_this_request_flask_app_example.py
Created June 13, 2017 20:30
Python flask after_this_request example on matching endpoint
from flask import Flask, g, request
from flask import render_template, redirect
app = Flask(__name__)
def after_this_request(f):
if not hasattr(g, 'after_request_callbacks'):
g.after_request_callbacks = []
g.after_request_callbacks.append(f)
return f
@m-x-k
m-x-k / test_requests.py
Created May 28, 2017 15:08
Python Unittest mock example: requests library
from unittest.mock import patch, Mock
from requests import Response
import requests
import unittest
def health_check(endpoint):
return requests.get(endpoint).status_code
class TestHealthCheck(unittest.TestCase):
@m-x-k
m-x-k / merge_two_dicts.py
Created May 27, 2017 10:19
Python (2 and 3) how to merge two dicts
x = {'a': 1, 'b': 2}
y = {'b': 3, 'c': 4}
def merge_two_dicts_python3():
z = {**x, **y}
print(z) # {'c': 4, 'a': 1, 'b': 3}
def merge_two_dicts_python2():
z = dict(x, **y)
print(z) # {'a': 1, 'c': 4, 'b': 3}
@m-x-k
m-x-k / cookiecutter_alias_setup.sh
Created May 15, 2017 12:28
cookiecutter commands: setup new basic projects
alias new-springboot-app='cookiecutter https://github.com/m-x-k/cookiecutter-spring-boot'
alias new-python-app='cookiecutter https://github.com/m-x-k/cookiecutter-python-flask'
alias new-react-app='cookiecutter https://github.com/m-x-k/cookiecutter-react'
alias new-java-app='cookiecutter https://github.com/m-x-k/cookiecutter-java'
alias new-elm-app='cookiecutter https://github.com/m-x-k/cookiecutter-elm'
alias new-scala-app='cookiecutter https://github.com/m-x-k/cookiecutter-scala'
alias new-golang-app='cookiecutter https://github.com/m-x-k/cookiecutter-golang'
alias new-play-app='cookiecutter https://github.com/m-x-k/cookiecutter-play'