Skip to content

Instantly share code, notes, and snippets.

View reicolina's full-sized avatar

Rei Colina reicolina

View GitHub Profile
@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
*/
@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 / 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 / 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 / flus-vs-redux-others.md
Last active April 25, 2016 03:08
Flux-Utils, Redux or Both?

A year ago, it was really hard to move away from writing Flux components in pure vanilla Javascript. The reason? there was a lot of Flux implementations (libraries) out there, but all of them were too young to be trusted in a production environment.

Within the last couple of months, Engineers at Facebook; the creators of Flux, have publicly endorsed one library: Redux, as well as their own Flux library, which includes new store classes that you can extend in order to implement your own ones without the boilerplate caused by Flux implementations written in vanilla Javascript.

So, which one to use? Well, it depends. Redux will require quite a refactor of your current flux application, specially if you already have several stores in place. This is because Redux advocates for having only one master store, instead of several ones. Also, The classic Flux dispatcher is now gone in Redux, and you will need to digest new concepts such as Reducers (for handling actions) and Middleware (for async API calls).

However,

@reicolina
reicolina / angular-two-dots.md
Last active May 10, 2017 21:53
AngularJS and why you need one or more “dots”

In Angular, it is recommended to add objects to a scope instead of primitive values (always having one or more “dots” when accessing your models)

The reason is: prototypical inheritance. As you know, Javascript is different from classical OOP; inheritance is done in a prototypical matter. Angular follows this pattern in a way that scopes inherit prototypically from their parent scopes.

When implemented incorrectly, two-way data binding breaks if you have two or more nested elements that use separate controllers that point to the same model. Here is why:

Imagine you have two nested elements:

@reicolina
reicolina / outloolk-email-design.md
Last active November 10, 2015 19:27
Email Design: Images not showing on Outlook 2007, 2010, and 2013

Internet Explorer has a security setting that, when enabled, prevents Outlook from displaying images with a secure URL. (Image URLs starting with "http" will display, not URLs that start with "https".)

If Outlook 2007, 2010, or 2013 displays some - but not all - images, you may need to change the setting in your Internet Explorer web browser or desktop software.

To change the setting in Internet Explorer:

  1. Open Internet Explorer.
  2. Go to Tools > Internet Options.
  3. Click the Advanced tab.
  4. Scroll down to the Security settings list, then uncheck the "Do not save encrypted pages to disk" option.
@reicolina
reicolina / input-field-losing-focus.md
Last active November 10, 2015 23:26
AngularJS: Losing focus on fields inside a ng-repeat

I was recently presented with a bug, where an input field inside a list controlled by a ng-repeat kept losing focus everytime the data in the scope changed in the background.

The ng-repeat in question was written like this: ng-repeat="message in messages", and we had a service fetching messages every 10 seconds that did something like: scope.messages = messages

This totally makes sense, and technically there is nothing wrong with it, however, by design, ng-repeat triggers itself when the data being wathed (in this case messages) gets replaced with a new array. This "DOM refresh" could make input fields in the list to lose focus, and even worst, this could represent a huge performance hit when dealing with long arrays of data.

The solution? You can now add a track by $index to your ng-repeat:

ng-repeat="message in messages" track by $index

@reicolina
reicolina / cla-assistant.md
Last active November 8, 2021 08:52
GIthub Inegration with CLA Assistant

Integrating your Github repo with CLA Assistant (https://cla-assistant.io/) to handle Contributor License Agreements (CLA) signing.

Visual Demo:

Setup Instructions:

  • Go to https://cla-assistant.io/ and sign in with Github. Make sure that you also Grant access to your organization (if applicable)
@reicolina
reicolina / technical-papers-reading-list.md
Last active June 9, 2016 15:01
Techinal Papers Reading List

This is a list of technical papers that I have either read or added to my to-read list. These papers are categorized by topic in no particular order:

Artificial Intelligence

Machine Learning