Skip to content

Instantly share code, notes, and snippets.

View pfac's full-sized avatar

Pedro Costa pfac

View GitHub Profile
@pfac
pfac / application_controller.rb
Created May 18, 2019 12:56
Rails API authentication goodies
class Api::HelloController < Api::ApplicationController
include ActionController::HttpAuthentication::Token::ControllerMethods
def authenticate_user!
authenticate_or_request_with_http_token do |token|
# decode and/or verify token (!)
end
end
end
@pfac
pfac / README.md
Last active November 20, 2018 11:12
TIL 2018-11-20: String replacement in an Ansible Playbook

String replacement in an Ansible Playbook

Ansible is built with Python, and many things in there relate to the way Python works. String replacement, however, is slightly different. Trying to run the following playbook:

---
- tasks:
  - debug:
 msg: "{{ string.replace('something', 'some', 'any') }}"

Keybase proof

I hereby claim:

  • I am pfac on github.
  • I am pfac (https://keybase.io/pfac) on keybase.
  • I have a public key whose fingerprint is DFD4 8013 2972 0973 3406 3A82 738D E401 04DC F849

To claim this, I am signing this object:

@pfac
pfac / gopro
Created September 22, 2016 18:08
MirrorConf
#!/bin/sh
curl -H "Accept: text/json" http://10.5.5.9:8080/gp/gpControl/execute?p1=gpStream&c1=restart
killall python3
(python3 hero4-udp-keep-alive-send.py > /dev/null) &
ffplay -fflags nobuffer -f:v mpegts -probesize 8192 -framedrop -fs udp://:8554
@pfac
pfac / labelize.rb
Last active June 24, 2019 17:13
A demo snippet for adding some text to an image using ImageMagick
#!/usr/bin/env ruby
# convert \
# -font '/Library/Fonts/Comic Sans MS Bold.ttf' \
# -pointsize 48 demo.png \
# -fill yellow -annotate +50+100 'Merry Christmas' \
# -fill white -annotate +50+170 'Helen' \
# wtf.png
require 'mini_magick'
@pfac
pfac / README.md
Created November 16, 2015 17:50
Carrierwave upload with darken filter

Carrierwave upload with darken filter

Simple demo of a Carrierwave uploader that uses MiniMagick to darken the uploaded images.

@pfac
pfac / form_cancel_url.rb
Created April 17, 2015 08:43
[Rails] Form cancel url
def form_cancel_url(*models)
Rails.root unless models.empty?
last_idx = models.length - 1
names = []
models.each_index do |idx|
model = models[idx]
if model
name = model.class.name.tableize
name = name.singularize unless model.new_record?
@pfac
pfac / ninja_macros.ex
Created March 17, 2015 17:41
Recursive macros failed attempt
defmodule Ninja.Macros do
defmacro __using__ [{ :name, value } | options] do
{:__block__, [], [
quote do
@name unquote value
def name, do: @name
end,
__MODULE__.__using__(options)
]
@pfac
pfac / index.md
Last active August 29, 2015 14:14
Ember notes

Don't use Ember.js for low interactivity cases like:

  • blog
  • static content

root

var App = Ember.Application.create(options);
@pfac
pfac / README.md
Last active August 29, 2015 14:09
Cron format

Cron format

<seconds> <minutes> <hours> <day of month> <month> <day of week> (<year>)

Examples

0 0 12 * * ?                  Fire at 12pm (noon) every day
0 15 10 ? * *                 Fire at 10:15am every day