Skip to content

Instantly share code, notes, and snippets.

View wikiti's full-sized avatar
🚀
I are prrugrameeng 🚀

Daniel Herzog wikiti

🚀
I are prrugrameeng 🚀
View GitHub Profile
@wikiti
wikiti / bash.sh
Last active October 9, 2018 08:35
Restart pulseaudio drivers, useful if sound does not work.
# Run this command on a terminal:
pulseaudio -k && sudo alsa force-reload
@wikiti
wikiti / trie.rb
Last active August 1, 2018 09:23
A simple implementation for a trie tree in ruby. For more information, check this: https://en.wikipedia.org/wiki/Trie
# A basic ruby implementation for the trie structure.
class Trie
# Node class to store node information (character or tag, and action)
class Node
attr_reader :children, :tag
attr_accessor :value
def initialize(tag, parent, action = nil)
@tag = tag
parent.children << self if parent
@wikiti
wikiti / pubsub.rb
Last active June 4, 2018 08:38
Ruby pub-sub implementation example
class Pubsub
class EventBus
attr_reader :topics
def initialize
@topics = {}
end
def publish(topic, message)
topics[topic.to_s].to_a.each do |subscriber|
@wikiti
wikiti / bash.sh
Last active May 4, 2018 08:55
Create a MongoDB backup with mongodump
# Run in a shell the following command:
mongodump
# A `dump` folder will be created on the current working directory.
# To compress that folder, use dump.
tar -czvf backup.tar.gz dump/
@wikiti
wikiti / bash.sh
Last active November 5, 2023 22:32
Backup and restore in PostgreSQL using compressed backups.
# List databases
sudo su postgres
psql
\list
# Create a compressed backup
sudo su postgres
pg_dump -Fc <database_name> > <file>
# Example
@wikiti
wikiti / human_size.js
Last active June 19, 2017 10:48
Human byte size
var toHumanSize = function(bytes) {
var list = ['B', 'kB', 'MB', 'GB', 'TB']; // Add more units, if you need to.
var factor = 1.0 / 1000.0; // You can use 1024 for bits instead!
var unit = list.shift();
while(list.length > 0 && bytes * factor >= 1) {
bytes = bytes * factor;
unit = list.shift();
}
@wikiti
wikiti / install.sh
Last active September 24, 2016 16:56
Bash | Install an executable file (tar.gz) from a Github repository
# This script will allow you to create an installation script, which will download a release from a GitHub repository,
# and install it on /usr/local/bin, accessible by user's PATH. The release file should include an executable, without any
# subfolders. After tweaking this file, you may now add it to your
# repository at your root as `install.sh` in the master branch. Users may run this script with:
#
# curl -s https://raw.githubusercontent.com/<user>/<repo>/master/install.sh | sh
#
# Custom configuration
@wikiti
wikiti / ubuntu-bootstrap.sh
Last active September 10, 2019 10:33
Bash | Custom configuration script for ubuntu
#!/bin/bash
# ---------------------------------------
# Local variables
# ---------------------------------------
name="<Your name>"
email="<Your email>"
dev_directory=~/Dev
work_directory=$dev_directory/Repos
bash_profile=~/.bashrc
@wikiti
wikiti / spiral_matrix.rb
Last active September 6, 2022 05:11
Print or traverse a matrix in spiral order using Ruby language
# Helper method to clone objects
def deep_clone(object)
Marshal.load(Marshal.dump(object))
end
# The concept y pretty simple: imagine that you have the following matrix:
# 1 2 3 4
# 10 11 12 5
# 9 8 7 6
#