Skip to content

Instantly share code, notes, and snippets.

Vlad GURDIGA gurdiga

Block or report user

Report or block gurdiga

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@gurdiga
gurdiga / getCookieByName.js
Last active Feb 25, 2016
A little function to get a cookie by name. Useful to debug from the the browser console.
View getCookieByName.js
function getCookieByName(name) {
return unescape(
(document.cookie.split(/; /g)||[])
.filter(function(pair) {
return pair.split('=')[0] === name;
})[0]
.split('=')[1]
);
}
View per-directory-bash-history.md

Per-directory Bash history (w/o aliasing cd)

I use Bash’s PROMPT_COMMAND variable:

The value of the variable PROMPT_COMMAND is examined just before Bash prints each primary prompt. If PROMPT_COMMAND is set and has a non-null value, then the value is executed just as if it had been typed on the command line.

The source code should be pretty straight forward, but if not, please ask in the comments. Put this in your .bashrc or similar:

# per-directory Bash history
View JS interface composition with promises.md

JS interface composition with promises

Inspired by Mr. Robert C. Martin’s episodes on SOLID principles that I’ve watched lately, and by the idea of “programming to interfaces” I’ve tried to come up with a schema that would allow me to have the concerns separated, but still composable.

These are a few modules from an Angular project.

So, I have an AuthenticationService module that does user account house-keeping:

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

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 Oct 8, 2013
Grunt task to run jasmine-node without PhantomJS when you don’t need it.
View grunt-task-jasmine-node.md

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 Oct 3, 2013
Personalized Web Options for Wikipedia
View Wikipedia.css
#mw-content-text {
width: 40em;
}
#toc {
float: right;
margin: 0 0 1em 1em;
}
@gurdiga
gurdiga / Kindle Library.html
Created Sep 30, 2013
Personalized Web Options for Kindle Library to delete an item with a double click.
View Kindle Library.html
<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 Mar 1, 2019
JS AES encryption example.
View aes-encryption-example.md

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();
You can’t perform that action at this time.