Skip to content

Instantly share code, notes, and snippets.

View CasperCL's full-sized avatar

Casper CasperCL

  • Amsterdam
View GitHub Profile
@CasperCL
CasperCL / knapsack_overflow.py
Created September 30, 2019 07:32
Knapsack Overflow Problem
"""
Solves the Knapsack overflow problem.
In this problem, we attempt to fill a Knapsack with items.
The constraints:
- The Knapsack may not underflow (i.e. the Knapsack must have no space left)
- The Knapsack may overflow
- The value of items should be minimized
- The quantity should be minimized
@CasperCL
CasperCL / gradient_descent.py
Last active August 11, 2019 19:26
Gradient Descent (Linear regression)
import random
X_Y = [(2, 4), (3, 6), (4, 9), (5, 10), (6, 12), (7, 15), (8,17), (9,20)]
w = [1, 2, 3, 4]
a = 0.0001
iterations = 15000
h = lambda x: w[0] * x**3 + w[1] * x**2 + w[2]*x + w[3]
l = lambda x, y: (h(x) - y)**2
dl = lambda x, y, w_: 2.0 * (h(x) - y) * w_
@CasperCL
CasperCL / Private-VPN.md
Last active February 13, 2020 09:26
Private VPN (On Demand)

Private VPN (On Demand)

Don't use VPN Services, roll your own.

8 steps to setup a private on demand VPN. With this setup you can spin up (and shutdown) a private VPN with just two buttons.

Prerequisites

@CasperCL
CasperCL / remove_chrome.sh
Last active December 9, 2019 11:30
Google Chrome removal
rm -r ~/Library/Application\ Support/Google
rm -r /Library/Application\ Support/Google
rm -r ~/Library/Caches/com.google.*
rm -r ~/Library/Caches/Google
rm -r ~/Library/Google
rm -r /Library/Google
@CasperCL
CasperCL / caesar.py
Last active February 19, 2019 20:38
Caesar Cipher
"""
Simple implementation of the Caesar cipher that works for the English alphabet
"""
alphabet = [chr(letter) for letter in range(97, 123)]
def caesar_cipher(text, key):
"""
Enciphers/deciphers a text.
@param text: to encipher/decipher
@CasperCL
CasperCL / cloudwatch-load-apache2-logs.sh
Last active December 17, 2018 13:17
Cloudwatch Load Apache2 logs
# /bin/bash
# Setup Cloudwatch config for Apache2 logs
ERROR_LOGS=( $( ls /var/log/apache2/*error.log ) )
ACCESS_LOGS=( $( ls /var/log/apache2/*access.log ) )
CONFIG_PATH="/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json"
CONFIG="{\"logs\":{ \"logs_collected\": { \"files\": { \"collect_list\": ["
LOGS=(${ERROR_LOGS[@]} ${ACCESS_LOGS[@]})
@CasperCL
CasperCL / install_python3.6.sh
Last active November 15, 2018 14:07
Install Python X.X + mod_wsgi on Linux from source
# !/bin/bash
# Source http://blog.dscpl.com.au/2015/06/installing-custom-python-version-into.html
PYTHON_VERSION="3.6"
sudo apt-get install apache2-dev -y
cd /tmp
git clone https://github.com/python/cpython.git
cd cpython
git checkout "$PYTHON_VERSION"
@CasperCL
CasperCL / mandelbrot.go
Last active May 10, 2018 15:56
Mandelbrot in Go 🏃‍♂️
package main
import (
"os"
"math"
"image"
"flag"
"image/png"
"image/color"
)
@CasperCL
CasperCL / markov.py
Last active May 10, 2018 16:07
Simple implementation of a Markov model
"""
A simple implementation of a n-gram (2-gram)
Markov model written for Python 3.6+
"""
import re
import random
from typing import List
from collections import defaultdict
@CasperCL
CasperCL / Pyramid.Dockerfile
Last active October 14, 2020 17:51
Docker for Pyramid
FROM python:3.6-alpine
RUN pip install gunicorn
COPY . /app
WORKDIR /app
RUN python setup.py develop
VOLUME ['/conf']