Skip to content

Instantly share code, notes, and snippets.

@karmi
karmi / nginx-elasticsearch-proxy.conf
Created May 23, 2011 08:16
Route requests to ElasticSearch to authenticated user's own index with an Nginx reverse-proxy
# Run me with:
#
# $ nginx -p /path/to/this/file/ -c nginx.conf
#
# All requests are then routed to authenticated user's index, so
#
# GET http://user:password@localhost:8080/_search?q=*
#
# is rewritten to:
#
@akalongman
akalongman / port_scanner.php
Created May 7, 2014 12:32
Port scanner on PHP
<?php
ini_set('max_execution_time', 0);
ini_set('memory_limit', -1);
$host = 'google.com';
$ports = array(21, 25, 80, 81, 110, 143, 443, 587, 2525, 3306);
foreach ($ports as $port)
{
$connection = @fsockopen($host, $port, $errno, $errstr, 2);
@andrewseidl
andrewseidl / Clang-format Comparison.md
Last active April 10, 2024 04:10
Clang-format style comparison

This is a comparison of the different formatting styles including with clang-format.

Generated via:

styles=( LLVM Google Chromium Mozilla WebKit )
for style in $styles
do
  clang-format -style=$style ChLcpIterativeAPGD.h > ChLcpIterativeAPGD.$style.h

done

@wolph
wolph / warning_decorator.py
Created October 5, 2015 09:08
Decorator to ignore a specific number of Python warnings
import warnings
import functools
def ignore_warning(warning, count=None):
def _ignore_warning(function):
@functools.wraps(function)
def __ignore_warning(*args, **kwargs):
with warnings.catch_warnings(record=True) as ws:
# Catch all warnings of this type
@yograterol
yograterol / gist:99c8e123afecc828cb8c
Created January 8, 2016 05:45
"gcc: error: /usr/lib/rpm/redhat/redhat-hardened-cc1: No such file or directory" workaround
"gcc: error: /usr/lib/rpm/redhat/redhat-hardened-cc1: No such file or directory" CentOS's and Fedora +22 workaround
Install `redhat-rpm-config`
$ sudo dnf install redhat-rpm-config
@mihow
mihow / load_dotenv.sh
Last active June 14, 2024 02:15
Load environment variables from dotenv / .env file in Bash
if [ ! -f .env ]
then
export $(cat .env | xargs)
fi
@fsteffenhagen
fsteffenhagen / sum_filesize.sh
Last active April 15, 2024 10:04
sum human readable file sizes with numfmt and awk
# Input: list of rows with format: "<filesize> filename", e.g.
# filesizes.txt
#######################
# 1000K file1.txt
# 200M file2.txt
# 2G file3.txt
#
# Output:
cat filesizes.txt | numfmt --from=iec | awk 'BEGIN {sum=0} {sum=sum+$1} END {printf "%.0f\n", sum}'
@BarelyAliveMau5
BarelyAliveMau5 / modified_utf8.py
Last active August 23, 2023 17:58
python's version of java's modified utf8
# translated from: http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/94cc251d0c45/src/share/npt/utf.c
def utf8s_to_utf8m(string):
"""
:param string: utf8 encoded string
:return: modified utf8 encoded string
"""
new_str = []
i = 0
while i < len(string):
@wtbarnes
wtbarnes / push-to-someone-elses-pr.md
Created March 5, 2020 04:49
Brief instructions for how to modify and push to someone else's PR on github

How to Push to Someone Else's Pull Request

Let's say contributor has submitted a pull request to your (author) project (repo). They have made changes on their branch feature and have proposed to merge this into origin/master, where

origin -> https://github.com/author/repo.git

Now say you would like to make commits to their PR and push those changes. First, add their fork as a remote called

@carc1n0gen
carc1n0gen / flask-domain-matching.py
Last active February 22, 2021 09:05
Flask Host Matching
from flask import Flask, url_for
app = Flask(__name__, host_matching=True, static_host='app1.local:5000')
@app.route('/', host='app1.local:5000')
def home1():
return url_for('home1')