Skip to content

Instantly share code, notes, and snippets.

View ivopt's full-sized avatar
🏠
Working from random places!

Ivo Jesus ivopt

🏠
Working from random places!
View GitHub Profile
@ivopt
ivopt / Dockerfile
Last active October 8, 2022 19:08
Pizza Place - Docker setup
FROM bitnami/git:latest
RUN apt-get update
RUN apt-get install -y --no-install-recommends --no-install-suggests less neovim
RUN echo "alias ll='ls -lah --color'" >> ~/.bashrc
WORKDIR /pizzaplace
CMD "bash"
@ivopt
ivopt / migrate.sh
Created June 9, 2020 10:12
Migrate from VSCode to VSCodium
# Export your extention list and your settings from VSCode
code --list-extensions | tee ~/vscode-extensions.txt
cp ~/Library/Application\ Support/Code/User/settings.json ~/vscode-settings.json
cp ~/Library/Application\ Support/Code/User/keybindings.json ~/vscode-keybindings.json
cp -r ~/Library/Application\ Support/Code/User/snippets ~/vscode-usersnippets
# Uninstall VSCode (may vary if you haven't installed through brew)
brew cask uninstall --force visual-studio-code
# Install VSCodium
brew cask install vscodium
@ivopt
ivopt / .editorconfig
Created December 12, 2017 22:23
an editorconfig.. config..
root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 2
@ivopt
ivopt / bm_merge_vs_add_and_sort.rb
Last active October 31, 2017 17:21
Merging vs Adding and Sorting 2 pre-sorted collections
require 'benchmark'
# ------------------------------------------------------------------------------
# Add 2 collections together and sort the result
def add_and_sort(left, right)
(left + right).sort { |a, b| b[:updated_at] <=> a[:updated_at] }
end
# ------------------------------------------------------------------------------
# Merge 2 previously ordered collections together
@ivopt
ivopt / pipe.rb
Last active July 10, 2019 16:13
Pipe Dreams
class Pipe
def self.unwrap
self
end
def self._unwrap(context, input, ops)
ops.inject(input) { |value, op| context.send(op, value) }
end
def initialize(context, input)
@ivopt
ivopt / delegation_bm.rb
Last active July 16, 2019 09:15
WoW, SimpleDelegator is REALLY slow...
require 'benchmark'
require 'active_support/core_ext/module/delegation'
# 6! = 720
METHODS = %w[a b c d e f].permutation.map(&:join)
class Decoratee
METHODS.each do |m|
define_method m do
m
@ivopt
ivopt / jsonandjq.java
Last active June 12, 2017 22:29
Parsing some JSON
// So, I have this JSON bellow and I want a subset of the fields to be mapped onto an existing entities:
// Book Entity
public class Book {
private String title;
private List<String> authors;
private String publisher;
private List<String> categories;
private List<Identifier> industryIdentifiers;
}
@ivopt
ivopt / module_attr_accessors.rb
Created December 17, 2013 22:41
module attribute accessors and defaults
class Module
# =============================================================================
def module_attr_reader opts
Array(opts).each do |m_name, default_value|
class_eval(<<-RUBY, __FILE__, __LINE__)
@@#{m_name} = default_value unless defined? @@#{m_name}
def self.#{m_name}; @@#{m_name}; end
RUBY
end
end
@ivopt
ivopt / hash_augmentations.rb
Created June 5, 2013 12:20
A few augmentations to Ruby Hash..
class Hash
def self.infinite
self.new{|h, k| h[k] = self.new(&h.default_proc)}
end
def self.recursive max = nil
if max && max.kind_of?(Fixnum)
self.new{|h,k| h[k] = self.recursive(max-1) if max > 1}
else
infinite