Skip to content

Instantly share code, notes, and snippets.

View lucivaldo's full-sized avatar
🏠
Working from home

Lucivaldo lucivaldo

🏠
Working from home
View GitHub Profile
@lucivaldo
lucivaldo / my_app.rake
Created April 27, 2016 14:52
Rake task for display all models of the application
namespace :my_app do
desc "Display all models"
task models: :environment do |t|
puts 'Tabelas existentes:', ""
ActiveRecord::Base.connection.tables.delete_if do |table|
table.include? 'schema'
end.each do |table|
puts "<<<< #{table} >>>>"
ActiveRecord::Base.connection.columns(table).each do |column|
source 'https://rubygems.org'
ruby '2.3.0'
gem 'rails', '4.2.6'
gem 'rake', '~> 11.1.2'
gem 'pg'
gem 'kaminari', '~> 0.16.3'
gem 'ransack', '~> 1.7.0'
gem 'devise', '~> 3.5.3'
@lucivaldo
lucivaldo / testa_ambientes.c
Last active June 6, 2016 17:43
Código em linguagem C para criar código específico para a plataforma Linux ou Windows dependendo do ambiente onde se estiver compilando.
#include <stdio.h>
#if defined(__linux__) || defined(__linux)
#define LINUX
#endif
#if defined(__WIN32__) || defined(__NT__)
#define WINDOWS
#endif
#!/bin/bash
cat /etc/lsb-release
@lucivaldo
lucivaldo / clm.sublime-snippet
Last active October 29, 2016 13:42
Snippet para o Sublime para gerar o corpo da classe com o método main
<snippet>
<content><![CDATA[
public class ${1:${TM_FILENAME/(.+)\..+|.*/$1/:name}} {
public static void main(String[] args) {
${2}
}
}
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>clm</tabTrigger>
@lucivaldo
lucivaldo / download_videos.rb
Created October 30, 2016 19:55
Fazer download dos vídeos de Dragon Ball Super do site de animes http://www.animakai.tv/
require 'open-uri'
require 'open_uri_redirections'
require 'nokogiri'
require 'pry'
LINKS_FILE = 'links.txt'
BASE_URL = 'http://www.animakai.tv'
NAMESPACE = 'anime/1877'
VIDEOS_DIRECTORY = 'videos'
@lucivaldo
lucivaldo / pre-commit
Created December 16, 2016 14:25
Script Ruby executado antes de efetuar o commit para interromper caso houver código de debug
#!/usr/bin/env ruby
require 'colorize'
files_with_debug = `git diff --name-only --cached | xargs grep -EH '^[^#]*binding.pry' | cut -d':' -f 1`
unless files_with_debug&.strip&.empty?
puts 'Tem código de debug nos seguintes arquivos:'
puts files_with_debug
exit(1)
@lucivaldo
lucivaldo / download.rb
Created November 16, 2017 14:51
Download file in Ruby with output of the progress
require 'net/http'
require 'pry'
def fetch(uri_str, limit = 30)
# You should choose a better exception.
raise ArgumentError, 'too many HTTP redirects' if limit == 0
uri = URI(uri_str)
use_ssl = uri.scheme == 'https' ? true : false
@lucivaldo
lucivaldo / change_wallpaper.py
Last active March 17, 2023 15:35
Script Python para alterar o wallpaper
#!/usr/bin/env python3
import glob
import os
import random
import time
PICTURES_PATH = os.path.join(os.path.expanduser("~"), "Pictures")
WALLPAPERS_PATH = os.path.join(PICTURES_PATH, "Wallpapers")
@lucivaldo
lucivaldo / change_wallpaper.rb
Last active April 20, 2020 13:33
Script Ruby para alterar o Wallpaper
#!/usr/bin/env ruby
module ChangeWallpaper
HOME = ENV['HOME']
PICTURES_PATH = HOME + '/Pictures'
WALLPAPERS_PATH = PICTURES_PATH + '/Wallpapers'
def self.change
wallpaper = Dir.glob("#{WALLPAPERS_PATH}/**/*").sample
command = "gsettings set org.gnome.desktop.background picture-uri #{wallpaper}"