Skip to content

Instantly share code, notes, and snippets.

View srMarquinho's full-sized avatar
🎯
Focusing

Marco Araujo srMarquinho

🎯
Focusing
View GitHub Profile
@srMarquinho
srMarquinho / mac-dock-spacer.txt
Created November 9, 2019 20:52
Organise Mac Dock by adding spacers
# Open terminal and type.
defaults write com.apple.dock persistent-apps -array-add '{tile-data={}; tile-type="small-spacer-tile";}';killall Dock
@srMarquinho
srMarquinho / awk_multiple_strings.sh
Created June 21, 2018 09:16
awk multiple strings - grep alternative
awk '/word1/&&/word2/&&/word3/&&/word4/' file
@srMarquinho
srMarquinho / virtualbox-macos_host-linux_ubuntu_guest-local_development.md
Last active August 2, 2019 08:06
Virtualbox - MacOS host - Linux Ubuntu guest - Local development

Local development setup

Set up VirtualBox with an Ubuntu virtual machine:

  • Sugested: RAM:2048MB, Storage:20GB

Create and mount a /dev folder from your Mac (Host) to the Ubuntu VM (Guest).

@srMarquinho
srMarquinho / ruby_shell_spinner.rb
Last active February 21, 2018 10:31
ruby_shell_spinner
# tested ruby 1.8
class Spinner
include Enumerable
def each
loop do
yield '|'
yield '/'
yield '-'
yield '\\'
@srMarquinho
srMarquinho / grep_snipet.sh
Created February 9, 2018 10:37
grep snipet
grep 'query' testing.log -B 5 -A 5 | less
@srMarquinho
srMarquinho / my_log.rb
Created February 7, 2018 10:27
custom rails logger
class MyLog
def self.debug(message=nil)
@my_log ||= Logger.new("#{Rails.root}/log/my.log")
@my_log.debug(message) unless message.nil?
end
end

Here's a useful one - If you ever need to check the methods of a ruby class/module (e.g. Math or User) you can call public_methods to get the class methods and public_instance_methods to get the instance ones.

The problem with this is that you'll also get entries for everything that it inherits from too, all the way up to Object methods like is_a? and send

To get around that, because they return arrays, you can subtract the result from calling it on the base class, e.g. Math.public_methods - Module.public_methods, or User.instance_methods - ActiveRecord::Base.instance_methods

@srMarquinho
srMarquinho / benchmark.rb
Created January 8, 2018 08:54
ruby benchmark snipet example
require 'benchmark'
n = (10**6)
Benchmark.bm(7) do |x|
x.report("1:") do
1.upto(n) do
#code
end
GET:
with JSON:
curl -i -H "Accept: application/json" -H "Content-Type: application/json" http://hostname/resource
as XML:
curl -H "Accept: application/xml" -H "Content-Type: application/xml" -X GET http://hostname/resource
curl -H "Accept: application/xml" "http://localhost:3040/api/org.xml"
curl -H "Accept: application/xml" -H "API_KEY: fgjfgjhfj68rvuIXy5XAlpRELmHKmOZNJeot62I3rePsnFAl15Wghjgs" "http://localhost:3040/api/org"
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
# Path to your oh-my-zsh installation.
export ZSH=/Users/marcoaraujo/.oh-my-zsh
# Set name of the theme to load. Optionally, if you set this to "random"
# it'll load a random theme each time that oh-my-zsh is loaded.
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
# ZSH_THEME="robbyrussell"