Skip to content

Instantly share code, notes, and snippets.

View rodrigoborgesdeoliveira's full-sized avatar

Rodrigo Borges de Oliveira rodrigoborgesdeoliveira

View GitHub Profile
rodrigoborgesdeoliveira /
Created January 26, 2023 14:30
Possible registry locations to find an installed program and get the product code from
  • HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
  • HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall
  • HKCU\Software\Microsoft\Windows\CurrentVersion\Uninstall
rodrigoborgesdeoliveira / winget-file-hash.ps1
Created January 26, 2023 14:21
Get file's hash using winget
winget hash --file <path-to-file>
rodrigoborgesdeoliveira / nginx-reverse-proxy-example
Created January 26, 2023 13:53
Nginx's reverse proxy example
server {
listen 80;
listen [::]:80 ipv6only=on;
access_log /var/log/nginx/server.access.log;
error_log /var/log/nginx/server.error.log;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
rodrigoborgesdeoliveira / gateway-example.ingress.yaml
Created June 6, 2022 16:53
An example of an ingress setup for a gateway on an nginx ingress on kubernetes.
kind: Ingress
annotations: |
if ($http_env = "dev") { proxy_pass http://<service-name>.<service-namespace>.svc.cluster.local:<service-port>; } # Point directly to a service in the same cluster
if ($http_env = "staging") { proxy_pass; } # Or point to a URL
name: gateway
namespace: default
# Continue as usual pointing to the default service
rodrigoborgesdeoliveira / setFieldToIdTimestamp.js
Created June 6, 2022 13:45
On MongoDB, update createdAt (or any other field) based on _id's timestamp
db.collection.updateMany({}, [{ $set: { createdAt: { $toDate: "$_id" } } }])
rodrigoborgesdeoliveira /
Created May 18, 2018 21:09
Get all android apps requested permissions
List<ApplicationInfo> packages = getPackageManager().getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo applicationInfo : packages) {
try {
PackageInfo packageInfo = getPackageManager().getPackageInfo(applicationInfo.packageName, PackageManager.GET_PERMISSIONS);
// Get all requested permissions for the current for loop package
String[] requestedPermissions = packageInfo.requestedPermissions;
// It's also possible to get if a permission has been granted to the current for loop package.
rodrigoborgesdeoliveira /
Last active November 12, 2021 22:36
Compare if a background of a view in android is equal to a specific resource id
// Comparing to a color
if (Objects.equals(view.getBackground().getConstantState(), activity.getResources().getDrawable(R.color.anyColor).getConstantState())) {
// Do what you have to do...
// Comparing to a drawable
if (Objects.equals(view.getBackground().getConstantState(), activity.getResources().getDrawable(R.drawable.anyDrawable).getConstantState())) {
// Do what you have to do...
rodrigoborgesdeoliveira /
Last active March 8, 2018 23:01
Names with special characters and a regex to block special characters that aren't used in names
  • Akan:
    • Nyankómàgó
    • Mǎnu
    • Meńsã́
    • Nsĩã́
    • Dúkũ
    • Ɔkwán
    • Nyamékyε
    • Obím̀pέ
rodrigoborgesdeoliveira /
Last active May 23, 2023 12:42
This shows or hides a floating action button when the recycler view is scrolled. It also adds a blank space after the list's last item to make sure that if the list is too short to be scrolled, it'll still be scrollable to hide the floating action button that is sitting on top of the last item.
// This code is inside the recycler view adapter class
public void onBindViewHolder(final ViewHolder holder, int position) {
if (position + 1 == getItemCount()) {
// It is the last item of the list
// Set bottom margin to 72dp
setBottomMargin(holder.itemView, (int) (72 * Resources.getSystem().getDisplayMetrics().density));
} else {
// Reset bottom margin back to zero
rodrigoborgesdeoliveira /
Created February 19, 2018 12:47
Manipulate Date in java.
* Returns a {@link Date} corresponding to the given Date plus time passed in milliseconds.
* @param startingDate The base Date used to get the future Date.
* @param timePassed The time (in milliseconds) to be added to the <b>startingDate</b>
* @return The {@link Date} in the future after <b>timePassed</b> milliseconds from <b>startingDate</b>.
public Date dateAfterMillis(Date startingDate, long timePassed) {
Date endingDate = new Date();
endingDate.setTime(startingDate.getTime() + timePassed);