Skip to content

Instantly share code, notes, and snippets.

View pawiromitchel's full-sized avatar
🔥
By doing nothing, you become nothing

Mitchel pawiromitchel

🔥
By doing nothing, you become nothing
View GitHub Profile
@pawiromitchel
pawiromitchel / copy.sh
Created June 8, 2021 11:53
Copy with a I/O throttle
# using the bwlimit parameter, you can limit the tx speed
rsync -r --progress --bwlimit=100 folder folder2
@pawiromitchel
pawiromitchel / compare_json_array.js
Created April 26, 2021 14:31
Compare Array with JSON objects to get removed and added objects
var array1 = [{id: 1}, {id: 2}, {id: 3}];
var array2 = [{id: 2}, {id: 4}];
var array1Converted = [];
var array2Converted = [];
// array met JSON objects omzetten tot normale arrays
array1.map(el => array1Converted.push(el.id));
array2.map(el => array2Converted.push(el.id));
@pawiromitchel
pawiromitchel / dynamic_object.js
Created April 20, 2021 14:48
Dynamisch object call based on a given string
var array1 = [1,2,3];
var array2 = [4,5,6];
// eval https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval
console.log(eval('array'+'2'))
@pawiromitchel
pawiromitchel / remove_empty_lines.sh
Created March 16, 2021 15:09
Remove empty lines from file
sed '/^$/d' file.csv > file_clean.csv
@pawiromitchel
pawiromitchel / mysql_replace_characters.sql
Created March 15, 2021 16:00
Replace in mysql function
CREATE DEFINER=`root`@`%` FUNCTION `REPLACE_SYMBOLS_WITH_TEXT`(field text) RETURNS text CHARSET utf8mb4
RETURN REPLACE(REPLACE(field, '!', '[uitroepteken]'), '#', '[hashtag]')
@pawiromitchel
pawiromitchel / dynamic_search_replace.js
Created March 11, 2021 15:06
Dynamic global search replace on records
var fields = [
"name",
"lastname"
]
var rules = {
"!": "[uitroepteken]",
"#": "[hashtag]",
}
@pawiromitchel
pawiromitchel / tz_difference.sh
Created November 26, 2020 21:57
Calculate datetime difference between 2 dates in #bash
Value1=$(TZ=Europe/Amsterdam date "+%F %H:%M:%S")
Value2=$(TZ=America/Paramaribo date "+%F %H:%M:%S")
Difference=$(($(date -d "$Value1" '+%s') - $(date -d "$Value2" '+%s')))
expr $Difference / 3600
@pawiromitchel
pawiromitchel / convert-a-datetime-from-another-timezone-to-browser-timezone.js
Last active November 18, 2020 17:29
convert a datetime from another timezone to browser timezone
function dateWithTimeZone(timeZone, year, month, day, hour, minute, second) {
var date = new Date(Date.UTC(year, month, day, hour, minute, second));
var utcDate = new Date(date.toLocaleString('en-US', { timeZone: "UTC" }));
var tzDate = new Date(date.toLocaleString('en-US', { timeZone: timeZone }));
var offset = utcDate.getTime() - tzDate.getTime();
date.setTime( date.getTime() + offset );
return date;
@pawiromitchel
pawiromitchel / resize_image.sh
Created November 13, 2020 03:18
Resize image with imagemagic convert utility
#!/bin/bash
# find $1 -maxdepth 1 -name "*.jpg" => finds JPG images in the directory you give it (based on the $1 value) that the script is in
# $1 is the directory you give the script for example "./resize_image.sh /home/folder_to_optimize/"
for file in `find $1 -maxdepth 1 -name "*.jpg"`
do
# convert the image and replace the original one
# throttle 50 = only use 50% of the cpu power
# 2500x = max 2500px, height will be automatically be adjusted based on the width
convert -limit throttle 50 $file -resize 2500x -verbose $file
@pawiromitchel
pawiromitchel / time_to_dec.js
Created November 2, 2020 16:06
JS: hh:mm:ss to hour decimal
function timeStringToFloat(time) {
var hoursMinutes = time.split(/[.:]/);
var hours = parseInt(hoursMinutes[0], 10);
var minutes = hoursMinutes[1] ? parseInt(hoursMinutes[1], 10) : 0;
var seconds = hoursMinutes[2] ? parseInt(hoursMinutes[2], 10) : 0;
return parseFloat((hours + (minutes / 60) + (seconds / 3600)).toFixed(2));
}