Skip to content

Instantly share code, notes, and snippets.

@vordan
vordan / loadConfigurationAndData.js
Created July 20, 2024 16:28
Asynchronous function to load a module-specific configuration script, execute it, and retrieve the configuration.
/**
* Asynchronous function to load a module-specific configuration script, execute it, and retrieve the configuration.
*
* Requirements:
* - URL parameter named 'module' which specifies the module name or pass the module name as an argument.
* - The module name in the URL or the argument can contain dashes which will be replaced with underscores to form the variable name.
* - Each module-specific script should define an asynchronous configuration variable using the naming convention:
* 'module_name_tabulator_edit_config'.
* - The scripts should be located at: 'session_data.app_http_root + local/tables/tabulator-edit/{module}.tabulator.js'.
*
@vordan
vordan / random_big_number.sql
Last active September 6, 2023 18:07
Generate random date between two dates in MySQL
select
concat(round(rand() * 10000),
round(rand() * 10000),
round(rand() * 10000),
round(rand() * 10000)
) as rnd
;
@vordan
vordan / locale.sh
Last active July 29, 2023 18:24
How-to fix "Warning: No support for locale: en_US.utf"
This is because locale-gen is using an archive file to store all the locales, but many utilities are still looking for the locale files.
Have a look at /usr/lib/locale/. If your output looks like this, read on:
ls /usr/lib/locale/
C.UTF-8 locale-archive
The warning isn't critical, as far as I can tell, but if it bothers you or causes troubles, try the following in a terminal window:
@vordan
vordan / accent-pf550.js
Last active June 27, 2023 16:25
Kodovi za rabota so fiskalen printer na Accent PF-550 (PF-500)
var codes_pf500 = {
adjust_date : Chr(61), // 3D
open_smetka : Chr(48), // 30
close_smetka : Chr(56), // 38
open_storno : Chr(85), // 55
close_storno : Chr(86), // 56
stavka : Chr(49), // 31
vtor_red : Chr(10), // 0A
kraj_opis : Chr(9), // 09
@vordan
vordan / build_tree.php
Last active February 5, 2023 09:13
Build a tree from a flat array in PHP
<?php
//--------------------------------------------------------
// Example:
//
// $cars = [
// ['id' => 999, 'value' =>'CARS', 'parent_id' => 0 ],
// ['id' => 11, 'value' =>'Toyota', 'parent_id' => 999],
// ['id' => 1, 'value' =>'Avalon', 'parent_id' => 11 ],
// ['id' => 2, 'value' =>'Corolla', 'parent_id' => 11 ],
// ['id' => 3, 'value' =>'Camry', 'parent_id' => 11 ],
<?php
/**
* Looks for unquoted keys in a json string and fixes them ie: {a:"b"} => {"a":"b"}
* @param string $string A json string that is suspect
* @return string A valid json string
*/
function fix_json($string){
// (no qupte) (word) (no quote) (semicolon)
$regex = '/(?<!")([a-zA-Z0-9_]+)(?!")(?=:)/i';
function getBase64FromImageUrl(url) {
var img = new Image();
img.setAttribute('crossOrigin', 'anonymous');
img.onload = function () {
var canvas = document.createElement("canvas");
canvas.width =this.width;
canvas.height =this.height;
@vordan
vordan / datatables.js
Created June 8, 2022 18:24 — forked from usmcamp0811/datatables.js
Custome PDF in DataTables Example
$(document).ready(function() {
// Function to convert an img URL to data URL
function getBase64FromImageUrl(url) {
var img = new Image();
img.crossOrigin = "anonymous";
img.onload = function () {
var canvas = document.createElement("canvas");
canvas.width =this.width;
canvas.height =this.height;
var ctx = canvas.getContext("2d");
@vordan
vordan / install_php5.3_on_ubuntu.txt
Created March 7, 2022 07:05 — forked from szihaj/install_php5.3_on_ubuntu.txt
How to install PHP 5.3 on Ubuntu
sudo add-apt-repository ppa:sergey-dryabzhinsky/php53
sudo apt-get update
sudo apt-get install php53-common php53-cli
# to see a list of available packages:
# apt-cache search php53
# ex.: sudo apt-get install php53-mod-mysql
# Apache module:
sudo apt-get install libapache2-mod-php53
@vordan
vordan / password.php
Created December 27, 2021 20:35
Generate and restore password hash #php #password #hash
// Save a password hash:
// ======================
$options = [
'cost' => 11,
];
// Get the password from post
$passwordFromPost = $_POST['password'];
$hash = password_hash($passwordFromPost, PASSWORD_BCRYPT, $options);