Skip to content

Instantly share code, notes, and snippets.

View aramalipoor's full-sized avatar
🎯
Focusing

aram.eth aramalipoor

🎯
Focusing
View GitHub Profile
@aramalipoor
aramalipoor / vagrant-ansible-virtualbox.sh
Created January 25, 2015 07:53
Install Virtualbox + Vagrant + Ansible + nfs
# You should enable Virtualization flag in your BIOS.
sudo apt-get install virtualbox vagrant ansible nfs-kernel-server
@aramalipoor
aramalipoor / ContainerInvalidator.php
Last active August 29, 2015 14:22
Symfony2 Container Cache Invalidator
<?php
namespace Sylius\Bundle\ThemeBundle\DependencyInjection;
use Sylius\Bundle\ThemeBundle\EventSubscriber\ContainerInvalidatorEventSubscriber;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface;
class ContainerInvalidator
@aramalipoor
aramalipoor / docker_get_env.sh
Created August 17, 2015 08:22
Bash helper function to get a specific environment variable from a Docker container
#!/bin/bash
# Retrieves an enviroment variable from a docker container
docker_get_env()
{
env_json=$(docker inspect --format '{{ json .Config.Env }}' ${1})
length=$(echo ${env_json} | jq '. | length')
for (( i=0; i<${length}; i++ ))
do
@aramalipoor
aramalipoor / score.php
Last active September 5, 2015 13:42
IAUN Score Match
<?php
session_cache_expire(0);
session_set_cookie_params(1000000000);
session_start();
$start_time = time();
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
@aramalipoor
aramalipoor / counter.js
Created November 4, 2015 08:43
AngularJS 1.x $watch counter
(function () {
var root = $(document.getElementsByTagName('body'));
var watchers = [];
var f = function (element) {
if (element.data().hasOwnProperty('$scope')) {
angular.forEach(element.data().$scope.$$watchers, function (watcher) {
watchers.push(watcher);
});
}
@aramalipoor
aramalipoor / README.md
Last active November 25, 2017 17:12
Re-commit snippet to commit your last commit again with same message to your remote, without adding a new commit to history

Install

sudo curl -L -o /usr/local/bin/recommit https://gist.githubusercontent.com/aramalipoor/fa0a501d985b095b4d8ec453e1ba8e56/raw/032275f887799c139a6b06e148b1146c914313b9/recommit.sh
sudo chmod +x /usr/local/bin/recommit

Disclaimer

Although this snippet checks last commit's ID on your remote branch before tying to force commit, use it at your own risk.

@aramalipoor
aramalipoor / Dockerfile
Last active November 23, 2023 14:05
Docker + Alpine + Newrelic + PHP (Kubernetes / AbarCloud)
# Prepare required directories for Newrelic installation
RUN mkdir -p /var/log/newrelic /var/run/newrelic && \
touch /var/log/newrelic/php_agent.log /var/log/newrelic/newrelic-daemon.log && \
chmod -R g+ws /tmp /var/log/newrelic/ /var/run/newrelic/ && \
chown -R 1001:0 /tmp /var/log/newrelic/ /var/run/newrelic/ && \
# Download and install Newrelic binary
export NEWRELIC_VERSION=$(curl -sS https://download.newrelic.com/php_agent/release/ | sed -n 's/.*>\(.*linux-musl\).tar.gz<.*/\1/p') && \
cd /tmp && curl -sS "https://download.newrelic.com/php_agent/release/${NEWRELIC_VERSION}.tar.gz" | gzip -dc | tar xf - && \
cd "${NEWRELIC_VERSION}" && \
@aramalipoor
aramalipoor / README.md
Last active February 22, 2018 17:18
Custom WRK (https://github.com/wg/wrk) script to count a response header useful for A/B load testing

Example

wrk -t 5 -c 10 -d 10s -s wrk-hostname-counter.lua https://example.com/

 ------------------------------------------------
 server-b-pxchg: 50.3333% (151 total)
 server-a-n82cc: 3.33333% (10 total)
 server-a-lr665: 3.33333% (10 total)
 server-a-7cnws: 3.33333% (10 total)

Nginx Config for real IP when using CloudFlare

If CloudFlare cache is disabled (the cloud icon in DNS settings is turned off, i.e. gray), the nginx config in our examples would work and gives you the real IP in REMOTE_ADDR variable.

If you need to keep CF cache enabled (the cloud icon is active and orange) adding code below to nginx config will give you user's real IP in REMOTE_ADDR variable:

server {
    // ...
    
    real_ip_recursive on;
    real_ip_header X-Forwarded-For;
@aramalipoor
aramalipoor / Dockerfile
Last active April 7, 2022 12:17
How to use Input Secrets to clone multiple repositories in OpenShift's BuildConfig?
FROM debian
RUN apt-get update -y && \
# SSH and git binaries are required
apt-get install -y curl ssh git && \
# Prepare required configurations and directories
mkdir -p /root/.ssh && \
git config --global user.name "example" && \