Skip to content

Instantly share code, notes, and snippets.

View arabcoders's full-sized avatar

Abdulmohsen arabcoders

View GitHub Profile
@arabcoders
arabcoders / post-mortem.md
Created April 12, 2017 17:28 — forked from joewiz/post-mortem.md
Recovery from nginx "Too many open files" error on Amazon AWS Linux

On Tue Oct 27, 2015, history.state.gov began buckling under load, intermittently issuing 500 errors. Nginx's error log was sprinkled with the following errors:

2015/10/27 21:48:36 [crit] 2475#0: accept4() failed (24: Too many open files) 2015/10/27 21:48:36 [alert] 2475#0: *7163915 socket() failed (24: Too many open files) while connecting to upstream...

An article at http://www.cyberciti.biz/faq/linux-unix-nginx-too-many-open-files/ provided directions that mostly worked. Below are the steps we followed. The steps that diverged from the article's directions are marked with an *.

    • Instead of using su to run ulimit on the nginx account, use ps aux | grep nginx to locate nginx's process IDs. Then query each process's file handle limits using cat /proc/pid/limits (where pid is the process id retrieved from ps). (Note: sudo may be necessary on your system for the cat command here, depending on your system.)
  1. Added fs.file-max = 70000 to /etc/sysctl.conf
  2. Added `nginx soft nofile 1
@arabcoders
arabcoders / README.md
Created December 2, 2016 08:09 — forked from nikcub/README.md
Facebook PHP Source Code from August 2007
@arabcoders
arabcoders / vpn.sh
Created October 6, 2016 12:15
generate ovpn file
#!/bin/bash
#Dir where easy-rsa is placed
EASY_RSA_DIR="/etc/openvpn/easy-rsa"
KEYS_DIR="$EASY_RSA_DIR/keys"
# Path to tls auth file.
TLS_AUTH_PATH="/etc/openvpn/ta.key"
# Dir where profiles will be placed
OVPN_PATH="/root/ovpn"
@arabcoders
arabcoders / converter.php
Created April 15, 2016 17:15 — forked from ShNURoK42/converter.php
Converter bbCode to markdown
protected function bbcode($bbcode)
{
$bbcode = str_replace("\n", " \n", $bbcode);
$bbcode = str_replace("[b]", "**", $bbcode);
$bbcode = str_replace("[/b]", "**", $bbcode);
$bbcode = str_replace("[i]", "*", $bbcode);
$bbcode = str_replace("[/i]", "*", $bbcode);
@arabcoders
arabcoders / post-receive.sh
Created September 30, 2015 19:31 — forked from ryansechrest/post-receive.sh
Git post-receive hook to deploy WordPress and plugins as submodules. It can also install Node.js modules with npm and vendor packages with Composer.
#!/bin/bash
# Created on 7/17/13 by Ryan Sechrest
# Deploys pushed branch from the origin repository to the web directory
if [[ (-n $1) && (-n $2) && (-n $3) ]]; then
# Set path to project directory
project_path="/var/www/domains/$2/$3"
@arabcoders
arabcoders / inArrayBind.php
Created May 12, 2015 15:46
This function is usefel if you want to use bind elements in PDO for IN clause for example: ( select * from table where id IN ( element, element) ... )
<?php
/**
* Create Binds for Array Elements.
*
* @param array $ids
*
* @return array
* @throws \InvalidArgumentException
*/
function inArrayBind( array $ids )
<?php
class SecureSessionHandler extends SessionHandler {
protected $key, $name, $cookie;
public function __construct($key, $name = 'MY_SESSION', $cookie = [])
{
$this->key = $key;
$this->name = $name;
@arabcoders
arabcoders / Twitter Instagram Cards
Last active August 29, 2015 14:13
This script is orginally written by Chris Bradbury and i took it and fixed some bugs such as CSP protection in chome since instagram still serve images over HTTP while the CSP in twitter disallow embeding any HTTP content., there is few things i want to do at long term such as using MutationObserver instead of looping and using twitter internal …
// ==UserScript==
// @name Twitter Instagram Cards
// @namespace http://arabcoders.co
// @author ArabCoders, Orginally Written By: Chris Bradbury
// @version 2.0.1
// @description Now that Instagram have pulled their twitter support, this script adds back inline instagram photos, fixed CSP in Chrome 29+
// @include https://twitter.com/*
// @require https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.js
// @grant setTimeout
// @grant GM_xmlhttpRequest
<?php
use PhpParser\Node;
use PhpParser\Node\Expr;
error_reporting(E_ALL);
ini_set('memory_limit', -1);
//$dir = __DIR__ . '/../../Symfony_2.3';
#!/bin/sh
#
# redis - this script starts and stops the redis-server daemon
#
# chkconfig: - 85 15
# description: Redis is a persistent key-value database
# processname: redis-server
# config: /etc/redis/redis.conf
# config: /etc/sysconfig/redis
# pidfile: /var/run/redis.pid