Skip to content

Instantly share code, notes, and snippets.

View franciscoj's full-sized avatar
🎯
Focusing

Fran Casas franciscoj

🎯
Focusing
View GitHub Profile
@franciscoj
franciscoj / ivar_vs_reader.md
Last active May 9, 2016 17:27
ivar vs reader

Ruby: ivar vs readers

Spoiler alert: Readers win.

  1. You don't rely on the instance state.
  2. You've better protection againt typos. @ivar might not exist and nothing will fail ivar will complain.
  3. They're easier to mock in specs in case you need to.
  4. They properly wrap the state so that refactors are easier
  5. they can be aliased
  6. they can be alias_method_chained
@franciscoj
franciscoj / vid2gif.sh
Created August 4, 2016 14:50
Transform a video into an animated gif.
#!/bin/sh
# Extracted from: http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html#usage
palette="/tmp/palette.png"
filters="fps=15,scale=640:-1:flags=lanczos"
ffmpeg -v warning -i $1 -vf "$filters,palettegen" -y $palette
ffmpeg -v warning -i $1 -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse" -y $2
@franciscoj
franciscoj / vim.diff
Created October 11, 2017 08:15
Better moving around on vim
-" Window move around
-nnoremap <silent><C-j> :wincmd j<CR>
-nnoremap <silent><C-k> :wincmd k<CR>
-nnoremap <silent><C-l> :wincmd l<CR>
-nnoremap <silent><C-h> :wincmd h<CR>
+" Move between windows
+nnoremap <silent><leader>j :wincmd j<CR>
+nnoremap <silent><leader>k :wincmd k<CR>
+nnoremap <silent><leader>l :wincmd l<CR>
+nnoremap <silent><leader>h :wincmd h<CR>
@franciscoj
franciscoj / list-resolution.sh
Created December 21, 2017 11:39
Get the resolution from a list of images
for file in *.png; do identify $file | awk '{print $1, $3}'; done
@franciscoj
franciscoj / unicodeces.vim
Last active April 17, 2018 12:49
Unicode things for Vim
" A couple of nice things your vim can use when you're dealing with unicode text.
" Taken from https://stackoverflow.com/questions/16987362/how-to-get-vim-to-highlight-non-ascii-characters
" Highlight all non ascii characters
syntax match nonascii "[^\x00-\xFF]"
highlight nonascii guibg=Red ctermbg=2
" Find any non ascii character
nnoremap <leader>na /[^\x00-\xFF]<CR>
@franciscoj
franciscoj / example.ex
Created October 5, 2018 08:17
Remove last line feed from multiline string in elixir
content = """
hello!
"""
assert content == "hello!\n"
content = """
hello!\
"""
@franciscoj
franciscoj / fira-code.conf
Last active October 28, 2018 12:01
Use Fira Code everywhere as monospace
<!-- ~/.config/fontconfig/fira-code.conf -->
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<match target="pattern">
<test qual="any" name="family"><string>monospace</string></test>
<edit name="family" mode="assign" binding="same"><string>Fira Code</string></edit>
</match>
</fontconfig>
# If a spec in the suite is marked with focus on the CI it will fail.
RSpec::Matchers.define :have_no_focus do
match { |ex| !ex.metadata[:focus] }
failure_message(&:inspect)
end
RSpec.configure do |config|
config.before(:each) do |example|
@franciscoj
franciscoj / docker-compose.yml
Last active June 5, 2021 18:45
Docker for local dev reverse proxy
version: '3'
services:
proxy:
image: traefik:v2.0 # The official Traefik docker image
network_mode: host # Allows traefik to talk to your host machine
ports:
- "80:80"
- "443:443"
- "8080:8080" # The Web UI
volumes:
# Config for a dev app with rails + webpacker
[http]
[http.routers]
[http.routers.https-to-webpack-dev-server]
rule = "Host(`domain.dev`) && PathPrefix(`/sockjs-node`)"
service = "webpack-dev-server"
entrypoints = ["https"]
priority = 2
[http.routers.https-to-webpack-dev-server.tls]