Skip to content

Instantly share code, notes, and snippets.

View jvahldick's full-sized avatar

Jorge Vahldick jvahldick

View GitHub Profile
@jvahldick
jvahldick / AESEncrypt.php
Created October 20, 2023 00:05
AES Encryption/Decryption in PHP
<?php
declare(strict_types=1);
final class AESEncrypt
{
private const CYPHER_ALGO = 'AES-256-CBC';
public function __construct(private readonly string $passPhrase)
{
@jvahldick
jvahldick / structs-to-map.go
Created June 4, 2020 07:32
[Go] Converts structs into map[string]interface{}
package structs
import (
"encoding/json"
"reflect"
)
func ConvertToMapViaReflection(s interface{}) map[string]interface{} {
var m map[string]interface{}
@jvahldick
jvahldick / reset-user-session.sh
Created February 13, 2020 07:59
OSX Remove the session from the logged the user
# List users that are already logged in
ps aux | grep loginwindow | grep -v grep | awk {'print $1'}
# Remove the session from the logged the user
# Be aware that the user might lose everything unsaved from their session
sudo kill -9 $(ps aux | grep the-chosen-user | grep loginwindow | grep -v grep | awk {'print $2'})
@jvahldick
jvahldick / restart-osx-audio.sh
Last active February 18, 2020 08:46
Restart the OSX audio which gets stuck for some reason
# Run the command on the terminal
sudo kill -9 $(ps aux | grep coreaudiod | grep sbin | awk '{print $2}')
@jvahldick
jvahldick / image-loader.js
Last active September 27, 2019 15:39
Solving an issue with lazy load images or images that are been uploaded.
class ImageLoader {
DEFAULT_MAX_ATTEMPTS = 10;
DEFAULT_RELOAD_DELAY = 1000;
delay;
maxAttempts;
constructor(options) {
if (typeof options === 'undefined') {
options = {};
@jvahldick
jvahldick / git
Last active October 30, 2019 09:52
Place the script on /usr/local/bin/git to change the name and email before executing the git command
#!/usr/bin/env bash
GIT_SCRIPT=$(which -a git | sed -n 2p)
# Does the remote "origin" point to GitHub?
if ("$GIT_SCRIPT" remote -v 2>/dev/null |
grep '^origin\b.*github.com.*(push)$' >/dev/null 2>&1); then
# Yes. Set username and email that you use on GitHub.
export GIT_AUTHOR_NAME='*** username ***'