Skip to content

Instantly share code, notes, and snippets.

View alissonbrunosa's full-sized avatar

Alisson Bruno alissonbrunosa

View GitHub Profile
class String
def red = "\e[31m#{self}\e[0m"
def cyan = "\e[36m#{self}\e[0m"
end
if defined? Rails
project_name = File.basename(Dir.pwd).cyan
envrionment = ENV['RAILS_ENV'].red
prompt = "(#{project_name}) -> [#{envrionment}]"
@alissonbrunosa
alissonbrunosa / vim.rb
Created December 29, 2021 14:52
Open constants and methods in Vim.
# frozen_string_literal: true
if Rails.env.development?
ActiveSupport::Reloader.to_prepare do
module OpenOnVim
def open_method(method_name)
file, line = method(method_name.to_sym).source_location
vim(file, line)
end
@alissonbrunosa
alissonbrunosa / main.go
Last active December 3, 2020 11:09
A small program to set your timezone based on your IP
package main
import (
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
"os"
"path/filepath"
package main
import (
"fmt"
"time"
)
func main() {
today := time.Now()
future := today.AddDate(0, 4, 0)
/*
Sort a linked list in O(n log n) time using constant space complexity.
Example 1:
Input: 4->2->1->3
Output: 1->2->3->4
Example 2:
/*
You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.
You may assume the two numbers do not contain any leading zero, except the number 0 itself.
Example:
Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)
Output: 7 -> 0 -> 8
Explanation: 342 + 465 = 807.
@alissonbrunosa
alissonbrunosa / hashtable.go
Created March 9, 2020 15:51
Simple implementaion of a Hashtable based on java.util.Hashtable.java
package hashtable
type Key interface {
HashCode() int
Equals(Key) bool
}
type entry struct {
hashCode int
key Key
def Ok(value)
Okay.new(value)
end
def Err(value)
Error.new(value)
end
class Result
attr_reader :value
@alissonbrunosa
alissonbrunosa / cities.go
Last active September 27, 2019 08:46
Implementation of BFS algorithm in Go
package bfs
import "fmt"
type City struct {
Name string
Population uint32
neighbors []Node
}
=begin
In this problem you will write a function called populate_template which will take in a template string e.g. " Hello {!first_name} - How are you?" and a hash of fields e.g { "first_name" : "John" } as arguments and will return the template string with the fields inserted in the correct place.
The usecase for a function like this would be for instance for answer templates to be used by a support team at a company.
So in the previous example you would get:
populate_template("Hello {!first_name} - How are you?", {"first_name" => "John"})
and you would get: