Skip to content

Instantly share code, notes, and snippets.

@lucas-tulio
lucas-tulio / mute.py
Created May 11, 2016 23:56
Spotify ad muter in Python
import os, dbus
from time import sleep
from subprocess import call
session_bus = dbus.SessionBus()
spotify_bus = session_bus.get_object("org.mpris.MediaPlayer2.spotify", "/org/mpris/MediaPlayer2")
spotify_properties = dbus.Interface(spotify_bus, "org.freedesktop.DBus.Properties")
while True:
metadata = spotify_properties.Get("org.mpris.MediaPlayer2.Player", "Metadata")
@lucas-tulio
lucas-tulio / sublime-settings.json
Created August 11, 2015 17:27
The settings I use in Sublime Text 2
// Settings in here override those in "Default/Preferences.sublime-settings", and
// are overridden in turn by file type specific settings.
{
"font_size": 16,
"tab_size": 2,
"translate_tabs_to_spaces": true,
"draw_white_space": "all"
}
@lucas-tulio
lucas-tulio / UsageStatsExample.java
Created August 4, 2015 20:12
Example of how to use UsageStats in Android
/**
* AndroidManifest.xml
*
* <uses-permission
* android:name="android.permission.PACKAGE_USAGE_STATS"
* tools:ignore="ProtectedPermissions" />
*/
/**
* In your Class
@lucas-tulio
lucas-tulio / sublime-keymap.json
Created March 17, 2015 17:16
Sublime Text 2 keyboard shortcuts on Linux using ABNT2 keyboard
[
{ "keys": ["ctrl+."], "command": "show_overlay", "args": {"overlay": "goto", "text": "#"} },
{ "keys": ["ctrl+;"], "command": "toggle_comment", "args": { "block": false } },
{ "keys": ["ctrl+shift+;"], "command": "toggle_comment", "args": { "block": true } }
]
@lucas-tulio
lucas-tulio / binary-number-sequence.sql
Created March 11, 2015 16:14
Generates a list of numbers in MySQL without using tables, loops or procedures
select
t8.num as bit8, t7.num as bit7, t6.num as bit6, t5.num as bit5, t4.num as bit4, t3.num as bit3, t2.num as bit2, t1.num as bit1,
(t1.num * 1) + (t2.num * 2) + (t3.num * 4) + (t4.num * 8) + (t5.num * 16) + (t6.num * 32) + (t7.num * 64) + (t8.num * 128) as soma
from (
((select 0 num) union all (select 1 num)) t1
cross join
((select 0 num) union all (select 1 num)) t2
cross join
((select 0 num) union all (select 1 num)) t3
cross join
@lucas-tulio
lucas-tulio / cpf-generator.sql
Last active September 5, 2021 16:09
Gerador de CPF em MySQL
select concat(substr(cpf, 1, 3), '.', substr(cpf, 4, 3), '.', substr(cpf, 7, 3), '-', first_dig, if(second_soma % 11 < 2, 0, 11 - (second_soma % 11))) AS cpf
from (
select cpf, first_dig, second_one+second_two+second_three+second_four+second_five+second_six+second_seven+second_eight+second_nine+second_ten AS second_soma
from (
select
cpf,
11*original_one AS second_one,
10*original_two AS second_two,
9*original_three AS second_three,
8*original_four AS second_four,
@lucas-tulio
lucas-tulio / android-build.sh
Last active November 13, 2015 21:36
Android apk build commands. Because I keep forgetting them.
# Create a debug keystore. When it asks for a password, enter "android"
# For a production keystore, change the filename (from "debug.keystore" to something else), the alias (from "androiddebugkey" to something else) and enter a different password
keytool -genkey -v -keystore debug.keystore -alias androiddebugkey -keyalg RSA -keysize 2048 -validity 10000
# Jarsigner
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore debug.keystore YourApp.apk androiddebugkey
# Zipalign
# If you get: `zipalign: command not found`, install Android SDK Build Tools 20+. If you can't do that, add the `zipalign` dir to your path. It should be `<sdk-home>/build-tools/<android-version>/`
zipalign -v 4 YourApp.apk YourApp-aligned.apk
@lucas-tulio
lucas-tulio / convert-encoding.sh
Created September 19, 2014 16:43
Converts the encoding of .java files from Mac Roman to UTF-8
echo "#############################################################################################"
echo "This script will recursively convert the encoding of all *.java files from Mac Roman to UTF8!"
echo "All java files in this dir and subdirs will be changed."
echo "Only files with special characters will be changed. Probably."
echo
echo "Data may be lost. Use it at your own risk!"
echo "#############################################################################################"
read -p "Sure? " -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[YySs]$ ]]