Skip to content

Instantly share code, notes, and snippets.

View gustavomazzoni's full-sized avatar

Gustavo Mazzoni gustavomazzoni

  • Rio de Janeiro, Brazil
View GitHub Profile
@gustavomazzoni
gustavomazzoni / socket-consumer.js
Last active November 5, 2019 22:12
Websocket architecture proposal - with actioncable and redux
//--- USAGE:
// After user is authenticated, Connects to WS
socket.connect(authHeaders);
// Then, Setup listeners for each WS channel
const sessionChannel = socket.join('SessionChannel');
sessionChannel.on('logout', data => dispatch(logoutSuccess()));
const orderChannel = socket.join('OrderChannel');
@gustavomazzoni
gustavomazzoni / flatten_array.rb
Last active May 18, 2016 18:29
Ruby code that flatten an array of arbitrarily nested arrays into a flat array. e.g. [[1,2,[3]],4] -> [1,2,3,4].
# Ruby code that will flatten an array of arbitrarily nested arrays of integers
# into a flat array of integers. e.g. [[1,2,[3]],4] -> [1,2,3,4].
# A tail recursion was adopted so the minimal amount of variables is added to the stack.
class Utils
def flatten_array(arr)
# if it's not array return nil
if !(arr.is_a? Array)
return nil
end