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 / 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 / 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
@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 --
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 / Price.java
Created May 21, 2011 19:48
An Observer design pattern implementation example based on Ruby's Observable API
import java.util.Random;
public class Price {
private int value;
public Price(int value) {
this.value = value;
}
public int getValue() {
@andersondias
andersondias / install.sh
Created May 12, 2010 14:59
Script to install basic apps on ubuntu
# Utils
sudo apt-get install htop
sudo apt-get install gnome-do
sudo apt-get install exuberant-ctags ncurses-term
sudo apt-get install vim-gnome
sudo apt-get install inkscape
sudo apt-get install sun-java6-jdk
sudo apt-get install compizconfig-settings-manager
sudo apt-get install ubuntu-restricted-extras