Skip to content

Instantly share code, notes, and snippets.

View diaz-de-berenguer's full-sized avatar

Diego Diaz de Berenguer diaz-de-berenguer

View GitHub Profile
@diaz-de-berenguer
diaz-de-berenguer / CanBeGrouped.rb
Created March 19, 2018 23:08
Determines whether a Graph can be divided in two groups, where the nodes in one group are not connected to the nodes in the second group
def assign_value(lib, left, right)
lib[left] = !lib[right] if lib[left] == nil
lib[right] = !lib[left] if lib[right] == nil
return lib
end
def can_be_grouped?(edges)
# Initialize lib - use first edge / first node
@diaz-de-berenguer
diaz-de-berenguer / app.js
Created February 5, 2018 19:00
Removing a User from an array
// Define WebSocket using ws library
const WebSocket = require('ws');
// Initialise wss as a new Websocket Server running in port 8989
const wss = new WebSocket.Server({ port: 8989 });
// Array of users currently logged in. Serves as the Database.
var users = [];
// This is the code that will run on the server when a new client is connected to
@diaz-de-berenguer
diaz-de-berenguer / pdf_file.rb
Last active February 2, 2022 23:52
Integration of generating PDF using 'wicked_pdf' and uploading to AWS using 'aws-sdk'
# This Rails Model can be used to generate a PDF, upload to AWS, and store bucket/key
# of the PDF. Uses Wicked PDF and the AWS SDK.
#
# Gems:
# gem 'aws-sdk' # https://github.com/aws/aws-sdk-ruby
# gem 'wicked_pdf' # https://github.com/mileszs/wicked_pdf
#
# Sources:
# https://github.com/thoughtbot/paperclip/wiki/PDF-Email-Attachments-with-Paperclip-and-wicked_pdf
# https://gist.github.com/micahroberson/5988843