Skip to content

Instantly share code, notes, and snippets.

View dcuadraq's full-sized avatar

David Cuadra dcuadraq

View GitHub Profile
@dcuadraq
dcuadraq / spacemacs.md
Last active July 30, 2018 21:41
Speacemacs cheat sheet

Spacemacs

Basic [Space] commands

Spc z f + Increase font size, press + until desired size, q for exit menu
Spc z f - Increase font size, press - until desired size, q for exit menu
Spc p f Search file by name in current project
Spc f s Save current buffer
Spc f S Save all buffers
Spc f t NerdTree toggle
R On NerdTree, sets higlighted directory as Root

@dcuadraq
dcuadraq / ch_01.md
Last active November 10, 2023 02:39
Rails Antipatterns: Best practice Ruby on Rails Refactoring notes

Chapter 1. Models

The Model layer should also contain the business logic of your application.

ANTIPATTERN: VOYEURISTIC MODELS

Class: A class defines the characteristics of an object, including the details of what it is (its attributes) and what it can do (its methods).

Method: A method exists on a class and defines what the class can do.

Encapsulation: Ideally, the code for a class should be relatively self-contained through encapsulation, which is the concealment of functional details of a class from the other objects that call its methods. This is typically done by limiting the methods other objects are allowed to call and exposing a public interface through which an object is exposed to the world. In Ruby, this is done with the public, protected, and private keywords.

@dcuadraq
dcuadraq / application.rb
Created July 24, 2017 17:11
Fix for Rails not reloading correctly for changes on controllers having Omniauthable
# config/application.rb
# Fix for Please add devise :omniauthable
initializer 'main_app.auto_load' do |app|
Rails.application.reloader.to_run(:before) do
Rails.application.reloader.prepare!
end
end
@dcuadraq
dcuadraq / iso_to_usb.md
Last active April 24, 2020 21:57
Extract ISO image content on USB

When attenpting to install a Linux Distro, its common to download the ISO then use a tool (e.g. UNetbootin, Linux Live USB Creator, Universal USB Installer, Live USB Creator) to make a USB bootable with the installer of the distro. This is no the recommended way.

Source

https://wiki.archlinux.org/index.php/USB_flash_installation_media

Prefered method

On OS X

To list USB devices

@dcuadraq
dcuadraq / tmux_cheat_sheet.md
Last active June 30, 2017 17:27
tmux cheat sheet

Tmux cheat sheet

Setup

brew install tmux

~/.tmux.conf

@dcuadraq
dcuadraq / fugitive.md
Last active June 19, 2017 00:49
Fugitive

Fugitive

Vim plugin for git

Commands

:help Glog

:Glog

:cnext

Loads the next version (older)

:cprevious

Loads the previous version (newer)

:cfirst

@dcuadraq
dcuadraq / 20170315153444_create_spree_state_translations.rb
Last active March 16, 2017 06:39
Add globalize to States on Solidus (2.1)
# db/migrate/20170315153444_create_spree_state_translations.rb
class CreateSpreeStateTranslations < ActiveRecord::Migration[5.0]
reversible do |dir|
dir.up do
Spree::State.create_translation_table! name: :string, abbr: :string
end
dir.down do
Spree::State.drop_translation_table!
end
@dcuadraq
dcuadraq / pg_search.md
Last active January 24, 2017 17:15
pg_search multilanguage support

Gem for searches using Postgresql.

Uses a dictionary to know the synonyms.

Query to get all currently available dictionaries

SELECT dictname FROM pg_catalog.pg_ts_dict; # or \dF

Query to get current default configuration

@dcuadraq
dcuadraq / examples.md
Last active December 21, 2016 17:19
rack-attack gem

Examples

Block requests with matching header

class Rack::Attack
  throttle('req/ip', limit: 0, period: 1.second) do |req|
    req.ip if req.env['HTTP_X_SCANNER'] == 'Netsparker' ||
              req.params['email'] == 'netsparker@example.com'
  end
end
@dcuadraq
dcuadraq / install_solidus.md
Last active January 11, 2018 07:20
How to install Solidus

#Solidus

Install imagemagick for thumbnail generation

brew install imagemagick

Create a new rails app

rails new solidus -d postgresql