Skip to content

Instantly share code, notes, and snippets.

function randomPassword(lenght) {
function random() {
return parseFloat('.' + crypto.getRandomValues(new Uint32Array(1))[0]);
}
var characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
password = '',
i;
for (i = 0; i < 10; i++)
mencoder dvd:// -mc 0 -noskip -ovc copy -oac copy -nosub -aid 131 -o Desktop/transcoded.avi

Web server comparison experiment: threaded Ruby vs. Node.js

Since a few weeks I’m working on a Node.js project at my day work, and I kind of loved the idea of the event loop, and then, because I just got off a Rails project, was wondering why wouldn’t that be possible with Ruby?

Googled a couple of evenings to find how Node.js manages to serve multiple requests on the same thread, and how its IO works. Then did the same for Ruby, read a bit about GIL, and found that in the end, there is not that much of a difference between what you can get from a threaded Ruby server and Node.js.

Played a bit with hello worlds and ended up with similar results from the speed and concurency standpoint: max 2 concurent requests on my 2CPU laptop.

For Ruby I spawn a separated Thread for every request. And from what I could google, Node.js uses a thread pool to handle the IO and one single other to run JS, which is kind of similar as far as I can understand these things. Now, I’ve tried hello world Rails and Sinatra proj

@gurdiga
gurdiga / grunt-task-jasmine-node.md
Created October 8, 2013 10:48
Grunt task to run jasmine-node without PhantomJS when you don’t need it.

Grunt task to run jasmine-node without PhantomJS

I’m working on a project where I write a webservice on Node.js and I find that grunt-contrib-jasmine is a bit slow to start. I couldn’t find amy module on npm that would do that, so I wrote my own task:

grunt.registerTask('jasmine', [], function() {
  var exec = require('child_process').exec,
      done = this.async();

  var child = exec('jasmine-node --matchall test', function(error, stdout, stderr) {

if (error) grunt.warn(error);

@gurdiga
gurdiga / Wikipedia.css
Created October 3, 2013 08:35
Personalized Web Options for Wikipedia
#mw-content-text {
width: 40em;
}
#toc {
float: right;
margin: 0 0 1em 1em;
}
@gurdiga
gurdiga / Kindle Library.html
Created September 30, 2013 06:49
Personalized Web Options for Kindle Library to delete an item with a double click.
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script>
var q = jQuery.noConflict(true);
q(function($) {
$('table#orderList').on('dblclick', 'tr[id~="collapse"]', function() {
var $tr = $(this),
sessionId = document.cookie.split(';')
.map(function(item) { return item.split('=', 2).map(function(token) { return token.toString().trim(); }); })
.filter(function(pair) { return pair[0] == 'session-id'; })[0][1];
@gurdiga
gurdiga / aes-encryption-example.md
Last active May 9, 2023 13:50
JS AES encryption example.

JS AES encryption example

This is a quick example of how to get symmetric encryption in JS using [aes.js from the crypto-js project][1]:

// at this point http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/aes.js should be loaded

var data = 'a JSON blob or something',
    password = 'my long and very secretive passphrase';

var encrypted = CryptoJS.AES.encrypt(data, password).toString();

@gurdiga
gurdiga / handlebars-partial.md
Last active December 23, 2015 21:39
Handlebars to emulate Rails partials with locals

Handlebars to emulate Rails partials with locals

I’ve created a little helper that takes a partial name and a Ruby-like hash of parameters that will be passed into that partial:

Handlebars.registerHelper('include', function(partialName, options) {
  var locals = options.hash,
      context = this;

  // the included partial also inherits the current context’s data

for (var property in context) {

@gurdiga
gurdiga / Facebook.css
Last active December 17, 2015 13:49
Personalized Web Options UI hack to hide “Recommended pages” and “Facebook © 2013” from the right-side panel. ^https://www.facebook.com/
#pagelet_ego_pane,
#pagelet_ego_pane_w,
#pagelet_rhc_footer,
#u_0_v {
display: none;
}
window.onload = function() {
setTimeout(function() {
console.log(document.forms.add_bkmk_form.annotation);
document.forms.add_bkmk_form.annotation.focus();
}, 100)
};