Skip to content

Instantly share code, notes, and snippets.

View farhadi's full-sized avatar

Ali Farhadi farhadi

View GitHub Profile
var http = require('http');
for (var i = 0; i < 10; i++) {
http.get({
host: 'localhost',
port: 80,
path: '/',
}, function(res) {
console.log(res.statusCode);
}).on('error', function(e) {
@farhadi
farhadi / autodir.js
Created January 25, 2012 07:48
jQuery plugin to automatically set direction on input/textarea fields.
(function($) {
$.fn.autodir = function() {
return this.each(function() {
$(this).on('keypress keyup change', function() {
$(this).css('direction', $(this).val().match(/^[^a-z]*[^\x00-\x7E]/ig) ? 'rtl' : 'ltr');
}).keyup();
});
};
})(jQuery);
@farhadi
farhadi / rc4.js
Created March 24, 2012 17:09
RC4 encryption in javascript and php
/*
* RC4 symmetric cipher encryption/decryption
*
* @license Public Domain
* @param string key - secret key for encryption/decryption
* @param string str - string to be encrypted/decrypted
* @return string
*/
function rc4(key, str) {
var s = [], j = 0, x, res = '';