Skip to content

Instantly share code, notes, and snippets.

View reicolina's full-sized avatar

Rei Colina reicolina

View GitHub Profile
@reicolina
reicolina / sortBy-method.md
Created November 7, 2015 15:41
Watch that _.sortBy() method!

It turns out that underscoreJS's .sortBy() method is case sensitive, so ordering arrays may not work the way you expect it if you have entities with different casing.

// Things  like 'myUser1' and 'MyUser2' will show out of order within a a given list, if using sortBy the following way:
users = _.sortBy(users, 'name');

//The proper way to do a case 'insensitive' sorting using underscore would be:
users = _.sortBy(users, function (user) {
	return user.name.toLowerCase();
});
@reicolina
reicolina / flux-vs-others.md
Last active November 7, 2015 15:40
Thoughts on Flux vs. Other Implementations

Personally, I don't think we would benefit much from 'flux-like' libraries if we don't fully understand what Flux, and specifically its dispatcher, is doing.

Taking Reflux as an example, the biggest difference between this library and Flux is that Reflux has no centralized dispatcher. Facebook’s developers (the creators of Flux) commented on this topic, by saying that not having a proper dispatcher may prevent your application from scaling well, and I do agree with that.

Flux is a very elegant solution to a well known data flow problem. If you've ever been on a situation where it seemed like data wasn't loading, or one component wasn't talking to another component, those problems are largely reduced (if not completely eliminated) if you do Flux properly and maintain the uni-directional flow that it promotes.

@reicolina
reicolina / P_1_6-compression.md
Created November 7, 2015 15:25
P1.6 Compression

P1.6 Compression: In P1.6 format, hexadecimal information is transferred: 3 hex bytes in 4 bytes in which the 7th bit is always 1 and the 8th bit (MSB) are reserved for parity. This type of compression is used in 'old school' devices such as the EMV modules inside some PIN entry devices (Payment PINPads). Here are VB methods for P1.6 encoding and decoding:

Friend Shared Function pP16Encode(ByVal yOriginalMessage As Byte()) As Byte()
    'Variable declarations
    Dim bitPosition As Integer = 1
    Dim origBitsPosition As Integer = 0
    Dim i As Integer

    'Convert the original bytes to a string of bits
    Dim sOrigBits As String = bytesToStringOfBits(yOriginalMessage)
@reicolina
reicolina / strobogrammatic.md
Last active November 7, 2015 15:24
Strobogrammatic Numbers

Once I was asked (as a challenge) to write an algorithm that finds numbers that, rotated 180 degrees, look exactly the same (strobogrammatic numbers). For some reason, that 'challenge' came up during a conversation I recently had with a co-worker, so I took some time to come up with a solution (in Java):

/**
* by: Rei Colina 
* A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down)
*
* To compile run: javac Strobogrammatic.java
* To run the test use: java Strobogrammatic
*/