Skip to content

Instantly share code, notes, and snippets.

View hamidreza-s's full-sized avatar

Hamidreza Soleimani hamidreza-s

View GitHub Profile
@hamidreza-s
hamidreza-s / Config - DNSRules.conf
Created March 31, 2014 08:41
Iptables rules for allowing incoming and outgoing DNS query.
# Rules for DNS
iptables -A OUTPUT -p udp --dport 53 --sport 1024:65535 -j ACCEPT
iptables -A INPUT -p udp --dport 53 --sport 1024:65535 -j ACCEPT
@hamidreza-s
hamidreza-s / Erlang - LebtusMiddlewareProposal.erl
Created January 8, 2014 17:57
Just a proposal for Lebtus framework to add use middleware.
-module(rq_handler).
-compile({parse_transform, leptus_pt}).
%% leptus callbacks
-export([init/3]).
-export([get/3]).
-export([use/3]).
-export([terminate/3]).
init(_Route, _Req, State) ->
@hamidreza-s
hamidreza-s / C - Pointers.c
Last active January 1, 2016 00:48
An example to how pointers in C work.
int main()
{
int i, j;
int *p;
p = &i;
*p = 5;
j = i;
printf("addresses: i = %d, j = %d, p = %d\n", &i, &j, p);
printf("values: i = %d, j = %d, p = %d\n", i, j, *p);
}
@hamidreza-s
hamidreza-s / NodeJs - InitScript.sh
Last active December 19, 2015 12:29
With this snippet of code you can create a Linux Init Script to be placed in "/etc/init.d/" an set it as a daemon with "chkconfig --add this" command.
#!/usr/bin/env bash
# chkconfig: 2345 20 80
# description: Description comes here....
start() {
# code to start app comes here
/path/to/forever start /path/to/app.js
}
stop() {
@hamidreza-s
hamidreza-s / NodeJs - Clustering.js
Created June 21, 2013 11:58
A single instance of Node runs in a single thread. To take advantage of multi-core systems the user will sometimes want to launch a cluster of Node processes to handle the load.
var cluster = require('cluster');
var http = require('http');
var numCPUs = require('os').cpus().length;
if (cluster.isMaster) {
// Fork workers
for (var i = 0; i < numCPUs; i++) {
cluster.fork();
}
@hamidreza-s
hamidreza-s / Shell - Install GitoLite.sh
Last active December 17, 2015 05:39
To have a private and fine grained git server you can follow these steps.
# On server (admin)
$ yum install git
$ useradd gitolite
$ passwd gitolite
$ su gitolite
$ cd
$ git clone git://github.com/sitaramc/gitolite.git
$ mkdir bin
$ gitolite/install -ln
$ gitolite setup -pk admin.pub
@hamidreza-s
hamidreza-s / PHP - Install AMQP Extension
Created May 5, 2013 06:44
Installing AMQP Extension for PHP in CentOS operation system. This will create an amqp.so shared object that needs to be included in your php.ini file. Find the extensions portal of the ini and add “extension=amqp.so”.
$ git clone git://github.com/alanxz/rabbitmq-c.git
$ cd rabbitmq-c
$ git submodule init
$ git submodule update
$ yum install libtool
$ yum install autoconf
$ yum install automake
$ yum install php-pear
$ yum install php-devel
$ make
@hamidreza-s
hamidreza-s / PHP - PhpWebCrawler.php
Created April 20, 2013 13:55
With this simple script you can grab content of your desired web site by DOM class of it. Have Fun!
<?php
// Set variables
$url = 'http://path/to/your/target';
$className = 'foo';
// Initialize CURL
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
@hamidreza-s
hamidreza-s / JavaScript - Classical OOP vs. Prototypal OOp.js
Created March 9, 2013 08:55
Object.create is new to JavaScript (it's part of ES5), but NodeJS supports it so we can safely use it. This creates a new object that inherits from another object.
// --- Classical OOP
function Person(name) {
this.name = name
}
Person.prototype = {
greet: function () {
return "Hello world, my name is " + this.name;
}
};
@hamidreza-s
hamidreza-s / MySQL - Import CSV.sql
Created January 22, 2013 07:19
Instead of writing a script to pull in information from a CSV file, you can link MYSQL directly to it and upload the information using the following SQL syntax. To import an Excel file into MySQL, first export it as a CSV file. Remove the CSV headers from the generated CSV file along with empty data that Excel may have put at the end of the CSV …
# Create Table
CREATE TABLE IF NOT EXISTS `foo_table` (
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`bar_column` varchar(10) NOT NULL,
`bat_column` varchar(10) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
# Load Data
load data local infile '/path/to/file.csv' into table `foo_table`