Skip to content

Instantly share code, notes, and snippets.

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

Anderson Dias andersondias

🏠
Working from home
View GitHub Profile
@andersondias
andersondias / script.js
Created February 5, 2024 15:31
Addition to Google's Vacation calendar template
// Add this to the shouldImportEvent method.
// Filters out events that are less than 4 hours long.
const millisecondsIn4Hours = 4 * 60 * 60 * 1000;
if (new Date(event.end.dateTime) - new Date(event.start.dateTime) < millisecondsIn4Hours) {
return false;
}
@andersondias
andersondias / App.js
Created July 8, 2022 17:23
Basic useApi React hook
import React from 'react'
function useApi(path) {
const api = `http://localhost:9000${path}`
const [state, setState] = React.useState({
loading: true,
data: null,
errors: null,
})
@andersondias
andersondias / script.rb
Last active May 21, 2020 18:49
Teste de NFs travadas
ids = %w(6675436 6675449 6675454 6675464 6675483 6675503 7114435 6675537 7114417 7115359 6675520 6675521 6675519 6675532 6675543 6675542 6675558 6675561 6675556 6675572 6675567 6675568 6675600 6675589 6675614 6675608 6675602 7114497 6675626 6675622 7114519 6675638 6675643 6675659 6675665 6675666 7114543 7114556 6675685 6675712 7114629 6675759 6675833 6675775 6675795 6675792 6675845 6675820 6675857 6675823 6675831 6675828 6675856 5090738 6675867 6675882 6675883 6675930 6675885 6675892 6675896 6675926 6675942 6675897 6675899 6675963 6675902 6675967 7114758 6675984 6676020 6675966 6676021 6675928 6675939 6675955 6675983 6675978 6675979 6675990 7114833 7114866 6676042 6676053 7114852 6676047 6676062 6676061 6676074 6676081 7114888 6676098 6676125 6676087 6676100 6676597 6676116 7114890 6676120 7114918); nil
Invoice.where(state: "waiting_order", id: ids).update_all(state: "title_integrated", provider_order_process_id: nil)
Setting.set(:send_invoice_to_mxm_worker_enabled, 'true')
ids.each do |id|
SendInvoiceToMx
@andersondias
andersondias / ordering.sql
Last active January 6, 2016 05:56
Ordering by nulls on Postgres
-- Default order will return NULL values at
-- the end of list
SELECT value FROM example ORDER BY value;
------------
-- value --
------------
-- 1 --
-- 2 --
-- 3 --
-- NULL --
@andersondias
andersondias / compare.rb
Last active December 28, 2018 14:00
How to compare version strings in Ruby
# Compares if a version is greater than other.
Gem::Version.new('2.1.15') > Gem::Version.new('1.14.1')
# => true
# It supports any number of minor versions
Gem::Version.new('2.0.0.1') < Gem::Version.new('2.0.1')
# => true
# And it deals with empty strings and nil values
Gem::Version.new('') < Gem::Version.new('2.0.1')
@andersondias
andersondias / git-release
Last active August 29, 2015 14:16
Git Release
#!/usr/bin/env ruby
# usage: git-release branch-name-1 branch-name-2 origin/remote-branch-name-3
branchs = ARGV[0..-1]
abort unless system("git checkout master")
abort unless system("git pull")
abort unless system("git remote prune origin")
system("gitk")
print("Informe qual a tag que será usada nesse release: ")
@andersondias
andersondias / Migration.md
Last active August 29, 2015 14:07
Updating to Yosemite

These are the steps I needed to take after installing Yosemite

  1. Java JDK error

The first error I've catch was an error in Java JDK. A popup was shown with this message: "To view this web content, you need to install the Java Runtime Environment."

Java error popup

In order to fix this, you need to install the latest Java 8 JDK.

require "bundler"
Bundler.setup(:default, :test)
require "active_record"
require "active_support"
@andersondias
andersondias / gitconfig.sh
Created April 12, 2013 17:47
Git configs
git config --global alias.s status
git config --global alias.a add
git config --global alias.d diff
git config --global alias.g grep
git config --global alias.b branch
git config --global alias.c commit
git config --global alias.co checkout
git config --global alias.mt mergetool
git config --global color.diff auto
git config --global color.status auto
@andersondias
andersondias / pomodoro.sh
Created August 18, 2011 14:50
Pomodoro Script for Ubuntu
# Dependencies: libnotify-bin sox
# Sound file download: http://www.soundjay.com/clock/alarm-clock-1.wav
DISPLAY=:0 notify-send -t 1000 -i ~/Pictures/icons/pomodoro.png "New Pomodoro starts" "You have 45 minutes to work."
while true; do
sleep 2700 # 45 minutes
DISPLAY=:0 notify-send -t 1000 -i ~/Pictures/icons/pomodoro.png "Pomodoro ends" "Take a break for 15 minutes!"
play ~/Music/effects/alarm-clock-1.wav
sleep 900 # 15 minutes
DISPLAY=:0 notify-send -t 1000 -i ~/Pictures/icons/pomodoro.png "New Pomodoro starts" "You have 45 minutes to work."
play ~/Music/effects/alarm-clock-1.wav