Skip to content

Instantly share code, notes, and snippets.

View elhoyos's full-sized avatar

Juan Hoyos elhoyos

View GitHub Profile
@elhoyos
elhoyos / gist:2159548a97a49045c4c8
Last active August 29, 2015 14:13
Update a document based on its current values
// Type in a mongoshell
// Credits: http://stackoverflow.com/questions/3788256/mongodb-updating-documents-using-data-from-the-same-document/3792958#3792958
db.currencies.find({symbol: "$"}).snapshot().forEach(
function (e) {
e.customSymbol = e.code.substr(0, 2) + e.customSymbol;
db.currencies.save(e);
}
);
@elhoyos
elhoyos / gist:53535f1067bf608119cf
Created October 6, 2014 05:08
Extracting from text files

Extracting from text files

Had the following:

/1-1-1/Screen16/screen.html
/1-1-2/Screen14/screen.html
/1-1-3/Screen12/screen.html
/1-1-3/Screen14/screen.html
/1-3-12/Screen15/screen.html
/1-3-8/Screen10/screen.html

Dealing with Java security message

This is what appear:

Java has discovered application components that could indicate a security concern. Contact the application vendor to ensure that it has not been tampered with.

Block potentially unsafe components from being run?

The reason

According to [Java][1] its because an Applet or a Java Web Start application contains mixed code (signed and unsigned).

@elhoyos
elhoyos / gist:7035a83efa6669a1e13c
Created October 6, 2014 05:07
How to know when an element is visible to the user
{
"dependencies": {
"heapdump": "^0.2.10"
}
}
@elhoyos
elhoyos / gist:ade5b69122bcdeba93fe
Last active August 29, 2015 14:06
Thread-safe code in Rails

Thread-safe code in Rails

It's not hard to write thread-safe code in a Rails application. Simple rules will save any app:

Don't share mutable state If you must share mutable state, mutex around all accesses to it

rails/rails#6685 (comment)

If config.threadsafe! is enabled and code is Non-threadsafe

@elhoyos
elhoyos / gist:ac462c921317394945fc
Created September 16, 2014 19:03
heapdump snippet
var heapdump = require("heapdump");
function handleCallback(err) {
callback(err);
gc();
process.nextTick(function () {
heapdump.writeSnapshot('/var/local/' + Date.now() + '.heapsnapshot', function() {
console.log('dump complete');
});
});
@elhoyos
elhoyos / gist:b2d850c3462d0ab691a9
Created August 5, 2014 16:22
Truncate to two decimal points (javascript)
Math.floor(number * 100) / 100;
@elhoyos
elhoyos / binary
Last active May 25, 2016 21:34
mongo: Copy a collection
$ mongodump -d some_database -c some_collection
$ mongorestore -d some_other_db -c some_or_other_collection dump/some_collection.bson
@elhoyos
elhoyos / gist:6cdedd5659de7110e9ca
Created June 19, 2014 22:02
Add your public ssh key as an authorized key
$ cat ~/.ssh/id_rsa.pub | ssh [email protected] 'cat >> .ssh/authorized_keys'