Skip to content

Instantly share code, notes, and snippets.

View mamapi's full-sized avatar

GregoryG mamapi

  • DevStream
  • PL
View GitHub Profile
@mamapi
mamapi / main.go
Created May 26, 2023 10:08 — forked from tomekbielaszewski/main.go
Example of RabbitMQ reconnect feature. Including recovering already registered consumers.
package main
import (
"fmt"
"log"
"time"
)
func main() {
queue := NewQueue("amqp://guest:guest@localhost:5672/", "hello")
@mamapi
mamapi / deploy.sh
Created February 11, 2023 22:11
Size all files in build_dir
if [[ $OSTYPE == "darwin"* ]]; then
full_size=$(find $build_dir ! -type d -print0 | xargs -0 stat -f '%z' | awk '{sum += $1} END{print sum}')
else
full_size=$(du -sb $build_dir | awk '{print $1}')
fi
@mamapi
mamapi / formatBytes.js
Created September 9, 2022 07:13 — forked from zentala/formatBytes.js
Convert size in bytes to human readable format (JavaScript)
function formatBytes(bytes,decimals) {
if(bytes == 0) return '0 Bytes';
var k = 1024,
dm = decimals || 2,
sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
}
// Usage:
@mamapi
mamapi / gist:a85ecd92909db5e9cee5f5eddd5b5c1b
Created June 7, 2022 17:52
Generate a cryptographically well-built artificial random data
 node -e "console.log(require('crypto').randomBytes(256).toString('base64'));"
@mamapi
mamapi / checkmark.js
Created November 5, 2021 17:14
Adds mark check symbol
const chalk = require('chalk');
/**
* Adds mark check symbol
*/
function addCheckMark(callback) {
process.stdout.write(chalk.green(' ✓'));
if (callback) callback();
}
@mamapi
mamapi / progress.js
Created November 5, 2021 17:13
Adds an animated progress indicator
const readline = require('readline');
/**
* Adds an animated progress indicator
*
* @param {string} message The message to write next to the indicator
* @param {number} amountOfDots The amount of dots you want to animate
*/
function animateProgress(message, amountOfDots) {
let i = 0;
@mamapi
mamapi / logging.go
Created July 9, 2021 12:48 — forked from panta/logging.go
zerolog with file log rotation (lumberjack) and console output
package logging
import (
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"gopkg.in/natefinch/lumberjack.v2"
"os"
"path"
"io"
)
@mamapi
mamapi / util.go
Created July 6, 2021 22:04
Golang - Create directory if not exists
package main
import "os"
func createDirIfNotExists(path string) error {
if _, err := os.Stat(path); os.IsNotExist(err) {
return os.Mkdir(path, os.ModeDir|0755)
}
return nil
}
@mamapi
mamapi / useFetchWithCache.js
Created March 9, 2021 12:30
React hook to fetch data with cache
import React, { useRef, useReducer } from 'react'
import { fetchJson } from 'apis'
export function useFetchWithCache({
url,
options,
}) {
const cache = useRef({})
@mamapi
mamapi / gist:0691ea44f102518539a3b6aef525a479
Created February 15, 2021 19:54
SQL Service Broker - New Broker Id
select service_broker_guid,* from sys.databases
ALTER DATABASE TEST_AUDIOKLAN SET NEW_BROKER WITH ROLLBACK IMMEDIATE;