Skip to content

Instantly share code, notes, and snippets.

Avatar

Ali Farhadi farhadi

View GitHub Profile
@farhadi
farhadi / rc4.js
Created Mar 24, 2012
RC4 encryption in javascript and php
View rc4.js
/*
* 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 = '';
@farhadi
farhadi / autodir.js
Created Jan 25, 2012
jQuery plugin to automatically set direction on input/textarea fields.
View autodir.js
(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);
View http-agent-bug.js
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) {