Skip to content

Instantly share code, notes, and snippets.

@lucabertolasi
lucabertolasi / format-currency.js
Last active March 4, 2018 20:48
[JavaScript] Format currency: from cents<number> to <string> or viceversa (e.g. 120030040 --> "1.200.300,40" --> 120030040).
/**
* @license
* Copyright (c) 2017-present, Luca Bertolasi. All Rights Reserved.
*
* This software is licensed under the terms of the MIT license,
* a copy of which can be found at https://opensource.org/licenses/MIT
*/
function formatCurrency(amount, strToNum) {
// default behaviour:
@lucabertolasi
lucabertolasi / _mixins.scss
Created March 4, 2018 20:35
[SCSS] Mixins
/**
* @license
* Copyright (c) 2017-present, Luca Bertolasi. All Rights Reserved.
*
* This software is licensed under the terms of the MIT license,
* a copy of which can be found at https://opensource.org/licenses/MIT
*/
@mixin background($attachment: scroll,
$clip: border-box,
@lucabertolasi
lucabertolasi / cordova_move_splashscreen_spinner_position_to_bottom.sh
Created March 4, 2018 20:33
[JavaScript] [Cordova] [cordova-plugin-splashscreen] Move splashscreen spinner position to bottom (iOS/Android).
#!/usr/bin/env node
/**
* @license
* Copyright (c) 2017-present, Luca Bertolasi. All Rights Reserved.
*
* This software is licensed under the terms of the MIT license,
* a copy of which can be found at https://opensource.org/licenses/MIT
*/
@lucabertolasi
lucabertolasi / httpInterceptor.factory.js
Created March 4, 2018 20:23
[JavaScript] [AngularJS] Interceptor to allow for cancelling requests.
/**
* @license
* Copyright (c) 2017-present, Luca Bertolasi. All Rights Reserved.
*
* This software is licensed under the terms of the MIT license,
* a copy of which can be found at https://opensource.org/licenses/MIT
*/
// To cancel the request, iterate over '$http.pendingRequests', find the nth request and call '$http.pendingRequests[nth].cancel.resolve()'
@lucabertolasi
lucabertolasi / cordova.database.factory.js
Last active March 4, 2018 20:16
[JavaScript] [AngularJS] [Cordova] [ngCordova] [$cordovaSQLiteSource] Cordova Data Objects
/**
* @license
* Copyright (c) 2017-present, Luca Bertolasi. All Rights Reserved.
*
* This software is licensed under the terms of the MIT license,
* a copy of which can be found at https://opensource.org/licenses/MIT
*/
// REQUIRES: http://ngcordova.com/docs/plugins/sqlite/
@lucabertolasi
lucabertolasi / cordovaHTTPool.js
Last active March 4, 2018 20:15
[JavaScript] [AngularJS] [Cordova] [cordovaHTTP] cordovaHTTPool avoids multiple cordovaHTTP requests to conflict, since they cannot be cancelled.
/**
* @license
* Copyright (c) 2017-present, Luca Bertolasi. All Rights Reserved.
*
* This software is licensed under the terms of the MIT license,
* a copy of which can be found at https://opensource.org/licenses/MIT
*/
// REQUIRES: https://github.com/wymsee/cordova-HTTP
@lucabertolasi
lucabertolasi / url-parser.js
Last active February 22, 2023 12:47
[JavaScript] A vanilla JS url parser.
/**
* @license
* Copyright (c) 2017, Luca Bertolasi. All Rights Reserved.
*
* This source code is licensed under the terms of the MIT license,
* a copy of which can be found at https://choosealicense.com/licenses/mit/
*/
function urlParser(url) {
// fallback to location object if no arg has been provided
@lucabertolasi
lucabertolasi / eval-or-google.js
Last active February 27, 2018 21:27
#just4fun | [JavaScript] Does your JS work? Evaluate it out! Google will come to rescue if necessary :)
/**
* @license
* Copyright (c) 2017, Luca Bertolasi. All Rights Reserved.
*
* This source code is licensed under the terms of the MIT license,
* a copy of which can be found at https://choosealicense.com/licenses/mit/
*/
function evalOrGoogle(str) {
const ELLIPSIS = `\u2026`
@lucabertolasi
lucabertolasi / bash_make_child_script_exit_parent_script.sh
Last active December 23, 2018 13:52
[Bash] How to exit the parent script if a child die? Call "./child.sh || exit 1" from the parent. Here an example:
#!/bin/bash
## LICENSE
## Copyright (c) 2017, Luca Bertolasi. All Rights Reserved.
##
## This source code is licensed under the terms of the MIT license,
## a copy of which can be found at https://choosealicense.com/licenses/mit/
cat << EOF > $(pwd)/parent.sh
#!/bin/bash