Skip to content

Instantly share code, notes, and snippets.

View acosonic's full-sized avatar
💭
I may be slow to respond.

Aleksandar Pavić acosonic

💭
I may be slow to respond.
View GitHub Profile
@acosonic
acosonic / demo.rake
Last active February 14, 2024 12:17
Redmine 5 demo data generator Put this in lib/tasks and install gem faker and gem random_data
# Still a work in progress but is good enough for development
#
# `rake redmine:demo_data` for it all
# `rake redmine:demo_data:users`
# `rake redmine:demo_data:projects`
# `rake redmine:demo_data:issues`
# `rake redmine:demo_data:time_entries`
require "faker"
require "random_data"
@acosonic
acosonic / loadcsvdates.sql
Created May 23, 2023 10:27
Load CSV file in MySQL serverside with fixing date formats
TRUNCATE TABLE `db`.`table`;
LOAD DATA LOCAL INFILE '/home/ubuntu/file.csv' IGNORE INTO TABLE `db`.`table`
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"' ESCAPED BY '"' LINES TERMINATED BY '\n' IGNORE 1 LINES (`id`, `Name`,
`Status`, `AccountNumber`, @v1,
@v2, `Business_Street`)
SET Formation_Date = STR_TO_DATE(@v1,'%m/%d/%Y'),
Production_Date = STR_TO_DATE(@v2,'%m/%d/%Y');
@acosonic
acosonic / pubip.sh
Last active May 26, 2023 17:03
Make pubip binary which determinates public ip
#!/bin/bash
wget -qO- http://acosonic.com/ip.php && echo -e "\r"
#you can use shc and compile this like shc -vrf pubip.sh -o pubip && mv pubip ~/bin
#then just use it as pubip from anywhere or move to system bin...
@acosonic
acosonic / resize.sh
Last active June 7, 2023 12:28
Ubuntu resize VM disk
#!/bin/bash
echo 1 > /sys/block/sda/device/rescan
cfdisk /dev/sda
pvresize /dev/sda3
lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
@acosonic
acosonic / memcached.sh
Created March 10, 2023 07:10
MemacheD (memcache with d) installation for PHP (run as root)
#!/bin/bash
apt install memcached libmemcached-tools
systemctl status memcached
echo stats | nc 127.0.0.1 11211
apt install php-memcached
phpenmod memcached
apache2ctl restart
@acosonic
acosonic / cleansnap.sh
Created January 9, 2023 20:43
Ubuntu 20.04 clean snap versions cache
#!/bin/sh
LANG=en_US.UTF-8 snap list --all | awk '/disabled/{print $1, $3}' |
while read pkg revision; do
sudo snap remove "$pkg" --revision="$revision"
done
@acosonic
acosonic / mysql_first.sh
Created January 9, 2023 06:29
Adding mysql auto increment primary key integer id field as first element to exiting table on the first place
ALTER TABLE somename ADD id int NOT NULL AUTO_INCREMENT primary key first
@acosonic
acosonic / adduid.sql
Last active January 9, 2023 20:42
Procedure for adding truly random UUID to existing tabe in mysql database with empty UUID varchar field Existing uuid function does not generate enough randomness
#change the exit criteria 61564999 to fit your needs
CREATE DEFINER=`root`@`localhost` PROCEDURE `adduuid`()
LANGUAGE SQL
NOT DETERMINISTIC
CONTAINS SQL
SQL SECURITY DEFINER
COMMENT ''
BEGIN
DECLARE a INT Default 1 ;
simple_loop: LOOP
@acosonic
acosonic / csv_to_mysql.js
Created January 6, 2023 09:14
Importing all csv files to mysql via nodejs from subfolder csv
// Assuming your sql has this global var set or you can set it via additional query:
// set global local_infile=true;
const mysql = require('mysql'); // or use import if you use TS
const util = require('util');
const fs = require("fs");
const conn = mysql.createConnection({
host: "localhost",
user: "root",
password: "pw",
@acosonic
acosonic / uuid.sql
Created December 24, 2022 23:49
Truly random MySQL uuid (taken from https://stackoverflow.com/a/60091504/800965)
UPDATE mytable SET uuid=(LOWER(CONCAT(
LPAD(HEX(ROUND(rand()*POW(2,32))), 8, '0'), '-',
LPAD(HEX(ROUND(rand()*POW(2,16))), 4, '0'), '-',
LPAD(HEX(ROUND(rand()*POW(2,16))), 4, '0'), '-',
LPAD(HEX(ROUND(rand()*POW(2,16))), 4, '0'), '-',
LPAD(HEX(ROUND(rand()*POW(2,48))), 12, '0')
)));