Skip to content

Instantly share code, notes, and snippets.

View AvnerCohen's full-sized avatar
🌍
Working from home

Avner Cohen AvnerCohen

🌍
Working from home
View GitHub Profile
[default]
aws_access_key_id = AKIHONEYPOTHONEYPPKA
aws_secret_access_key = juBYW/RHTE1ki+DyDFG/uPIhtwO9hm9+8+ErzMo9
honeypot = True
@AvnerCohen
AvnerCohen / nginx_install_more_headers.sh
Created November 5, 2017 13:15
Install nginx with clear_more_headers - Latest Version 1.13.6
yum update -y nginx
yum install -y pcre-devel
service nginx stop
mkdir ~/nginx_test
cd ~/nginx_test/
wget 'http://nginx.org/download/nginx-1.13.6.tar.gz'
tar -xzvf nginx-1.13.6.tar.gz
wget https://github.com/openresty/headers-more-nginx-module/archive/v0.33.tar.gz
tar -xzvf v0.33.tar.gz
cd nginx-1.13.6/
@AvnerCohen
AvnerCohen / install.sh
Last active October 27, 2023 22:26
Install Erlang + Rabbit MQ on AWS EC2 server
# erlang deps
sudo yum groupinstall "Development Tools"
sudo yum install ncurses-devel openssl-devel
# erlang
wget http://erlang.org/download/otp_src_20.1.tar.gz
tar -zxvf otp_src_20.1.tar.gz
rm -f otp_src_20.1.tar.gz
cd otp_src_20.1/
./configure
@AvnerCohen
AvnerCohen / python2.7.xx.bash
Last active October 25, 2018 10:12
Updated Python 2.7.xx on an Amazon AMI + make it default (in alternatives) and symlik pip ad virtualenv for future usage
#!/usr/bin/env bash
NEW_VERSION="2.7.14"
CURRENT_VERSION="$(python -V 2>&1)"
if [[ "$CURRENT_VERSION" == "Python $NEW_VERSION" ]]; then
echo "Python $NEW_VERSION already installed, aborting."
else
echo "Starting upgrade from ${CURRENT_VERSION} to ${NEW_VERSION}"
@AvnerCohen
AvnerCohen / delete_celery.js
Last active October 30, 2016 13:57
Mongo Query to Delete Celery succesfull entries on a large collection, slowly but surely.
var COUNTER = 900;
function deleteSome(count) {
var itemsToDel = db.tasks.find({status: "SUCCESS"}, {_id: 1}).sort({created_at: 1}).limit(count).toArray();
var IDs = itemsToDel.map(function(item){ return item["_id"]})
if (IDs.length > 0 ) {
db.tasks.remove({"_id": {"$in": IDs } });
sleep(5000);
} else {
COUNTER++;
@AvnerCohen
AvnerCohen / get_all_database_indexes_from_mongo.js
Created February 22, 2016 15:39
A script to print out all the indexes in all database of mongo
var db = db.getSiblingDB("admin");
var dbs = db.runCommand({ "listDatabases": 1 }).databases.sort();
dbs.forEach(function(database) {
db = db.getSiblingDB(database.name);
cols = db.getCollectionNames().sort();
cols.forEach(function(col) {
if (!db[col]) { return; }
db[col].getIndexes().sort().forEach(function(index) {
if ("_id_" !== index.name) {
print("at database: [" + database.name +"], db." + col + ".ensureIndex(" + tojson(index.key) + ")");
@AvnerCohen
AvnerCohen / git_aliases_setup.sh
Last active January 9, 2016 21:10
Random Git aliases and commands to
# Command: GLOG
# Description: alias that creates a nice and easy on eye history log with graph indication of merge commits and branches
git config --global alias.glog "\!git log --graph --pretty=format:'%Cred%h%Creset %an: %s - %Creset %C(yellow)%d%Creset %Cgreen(%cr)%Creset' --abbrev-commit --date=relative ; true"
# Run:
git glog
# Command: LASTWORKS
# Description: Lists the last 10 branches you worked on
git config --global alias.lastworks "for-each-ref --count=10 --sort=-committerdate refs/heads/"
@AvnerCohen
AvnerCohen / delete_branches_older_than.sh
Last active June 28, 2023 14:11 — forked from antonio/delete_branches_older_than.sh
Script to delete branches older than 6 months old, ignore local vs remote errors.
#!/bin/sh
ECHO='echo '
for branch in $(git branch -a | sed 's/^\s*//' | sed 's/^remotes\///' | grep -v 'master$'); do
if [[ "$(git log $branch --since "6 months ago" | wc -l)" -eq 0 ]]; then
if [[ "$DRY_RUN" = "false" ]]; then
ECHO=""
fi
local_branch_name=$(echo "$branch" | sed 's/remotes\/origin\///')
$ECHO git branch -d "${local_branch_name}"
@AvnerCohen
AvnerCohen / deploy.sh
Last active August 29, 2015 14:18 — forked from remy/deploy.sh
#!/bin/bash
readonly ARGS="$@"
readonly DEPLOY_USER="www-data"
clone_repo_at_tag() {
local repo="$1"
local tag="$2"
local project_name="$3"
local repo_dirname="$project_name-$tag"
@AvnerCohen
AvnerCohen / event_machine_sockets.rb
Created February 22, 2015 16:25
event machine + http event machine + em websocket, memory leaking like mad !!
require 'bundler'
require 'socket'
Bundler.require
WS_CLIENTS = {}
WS_CLIENTS_NAME_TO_SOCKET = {}
WS_HOST = Socket.ip_address_list.last.ip_unpack.first)
WS_PORT = 8090
HTTP_PORT = WS_PORT + 1