Skip to content

Instantly share code, notes, and snippets.

View thbar's full-sized avatar

Thibaut Barrère thbar

View GitHub Profile
@thbar
thbar / sync_foo_bar.rb
Last active March 1, 2017 08:31
Example of calling Kiba ETL from Sidekiq (I'll share more in an upcoming blog post)
require 'kiba'
require 'etl/csv_source'
require 'etl/sequel_upsert_destination'
require 'etl/dsl_extensions/add_timestamps'
require 'etl/dsl_extensions/remap_int'
require 'etl/dsl_extensions/fetch_and_rename'
require 'etl/dsl_extensions/raise_on_blanks'
$ rvm install 2.4.0
Searching for binary rubies, this might take some time.
Found remote file https://rvm_io.global.ssl.fastly.net/binaries/ubuntu/16.04/x86_64/ruby-2.4.0.tar.bz2
Checking requirements for ubuntu.
Missing required packages: bash curl patch bzip2 gawk g++ gcc libssl-dev make libc6-dev patch openssl curl zlib1g zlib1g-dev libyaml-dev libsqlite3-dev sqlite3 libgmp-dev libgdbm-dev libncurses5-dev bison pkg-config libffi-dev libgmp-dev libreadline6-dev
RVM autolibs is now configured with mode '2' =>
'Allow RVM to use package manager if found, fail if dependencies are missing. This is default.',
please run `rvm autolibs enable` to let RVM do its job or run and read `rvm autolibs [help]`
or visit https://rvm.io/rvm/autolibs for more information.
Requirements installation failed with status: 1.
@thbar
thbar / wordpress_importer.rb
Created February 14, 2017 13:37 — forked from stammy/wordpress_importer.rb
Import a WordPress database and generate markdown files for Jekyll
# View my Jekyll blog http://paulstamatiou.com and my jekyll migration post http://paulstamatiou.com/how-to-wordpress-to-jekyll/
#
#
# based on the import script by icebreaker, which is based on mojombo's
# https://github.com/mojombo/jekyll/blob/master/lib/jekyll/migrators/wordpress.rb
# https://gist.github.com/303570
# edited to rewrite image URLs to use my CloudFront URL
require 'rubygems'
require 'sequel'
@thbar
thbar / hello_world.exs
Created February 12, 2017 12:35
A sample kiba-ex ETL script (WIP)
defmodule SimpleETL do
use KibaEx
source CSVSource, filename: "source.csv"
transform RemapColumns
destination CSVDestination, filename: "destination.csv"
end
require "./spec_helper"
alias ConfigValue = String | Int32
alias Config = Hash(Symbol, ConfigValue)
class SomeSource
@filename : String
def initialize(options : Config)
@filename = options[:filename]
@thbar
thbar / replace_tag.rb
Created February 2, 2017 13:34
Useful snippet to reliably replace a XML element value
module ReplaceTag
extend self
def replace_tag(xml_as_string, selector, new_tag_value)
doc = Nokogiri::XML(xml_as_string)
matches = doc.search(selector)
unless matches.size == 1
fail "Expected exactly one match for selector #{selector}, got #{matches.size}"
end
matches[0].content = new_tag_value
@thbar
thbar / reloading.exs
Created October 29, 2016 11:32
Live code reloading with Elixir
# mix run --no-halt reloading.exs
# in music.exs, put:
#
# defmodule Music do
# def version do
# "3"
# end
# end
#
@thbar
thbar / gist:db63116c7d734a565b1161ed0b894949
Created October 6, 2016 12:38 — forked from alehmann/gist:316522
rubyrep / postgres: syncing tables with circular foreign key constraints
psql postgres -c "create database circular_fkeys_left"
psql circular_fkeys_left <<EOS
create table foos(id integer primary key, bar_id integer);
create table bars(id integer primary key, foo_id integer);
insert into foos(id, bar_id) values(1, 5);
insert into bars(id, foo_id) values(5, 1);
alter table foos add constraint bar_fk foreign key(bar_id) references bars;
alter table bars add constraint foo_fk foreign key(foo_id) references foos;
EOS
defmodule WisecashEx.AuthenticationTest do
use WisecashEx.IntegrationCase
setup do
%WisecashEx.User{email: "john@example.com"}
|> WisecashEx.User.auth_changeset(%{password: "testtest"})
|> Repo.insert!
:ok
end

#Simple Authentication with Bcrypt

This tutorial is for adding authentication to a vanilla Ruby on Rails app using Bcrypt and has_secure_password.

The steps below are based on Ryan Bates's approach from Railscast #250 Authentication from Scratch (revised).

You can see the final source code here: repo. I began with a stock rails app using rails new gif_vault

##Steps