Skip to content

Instantly share code, notes, and snippets.

View rodrigoborgesdeoliveira's full-sized avatar

Rodrigo Borges de Oliveira rodrigoborgesdeoliveira

View GitHub Profile
@rodrigoborgesdeoliveira
rodrigoborgesdeoliveira / ChangeNavigationDrawer.java
Last active December 8, 2017 17:23
Changing Headers and Menus from a Navigation Drawer
final NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.removeHeaderView(navigationView.getHeaderView(0)); // Remove old header
navigationView.inflateHeaderView(R.layout.nav_header_new_header); // Add and refresh new header
navigationView.getMenu().clear(); // Remove every element from the old menu
navigationView.inflateMenu(R.menu.new_drawer); // Add and refresh new menu
@rodrigoborgesdeoliveira
rodrigoborgesdeoliveira / dateAfterMillis.java
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);
@rodrigoborgesdeoliveira
rodrigoborgesdeoliveira / NamesSpecialCharacters.md
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
rodrigoborgesdeoliveira / AndroidRequestedPermissions.java
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
rodrigoborgesdeoliveira / compareBackgroundWithResourceId.java
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
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
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.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/configuration-snippet: |
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 https://staging.example.com; } # Or point to a URL
name: gateway
namespace: default
# Continue as usual pointing to the default service
@rodrigoborgesdeoliveira
rodrigoborgesdeoliveira / nginx-reverse-proxy-example
Created January 26, 2023 13:53
Nginx's reverse proxy example
server {
listen 80;
listen [::]:80 ipv6only=on;
server_name example.com www.example.com;
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
rodrigoborgesdeoliveira / winget-file-hash.ps1
Created January 26, 2023 14:21
Get file's hash using winget
winget hash --file <path-to-file>
@rodrigoborgesdeoliveira
rodrigoborgesdeoliveira / product-code-registry-locations.md
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