Skip to content

Instantly share code, notes, and snippets.

@adamrosloniec
adamrosloniec / gist:3ba3a2921466a7037bbf7e4299615aa9
Last active July 17, 2019 22:50
Regex - Polish Language with some (soft) special characters
var dataOld = ...;
var dataNew = dataOld.replace(/[^0123456789aąbcćdeęfghijklłmnńoópqrsśtuvwxyzźżAĄBCĆDEĘFGHIJKLŁMNŃOÓPQRSŚTUVWXYZŹŻ\ \!\"\#\$\%\&\'\(\)\+\,\.\/\:\;\<\=\>\?\@\[\]\_\`\{\|\}\–\—\‘\’\‚\“\”\„\…\-]/g, '');
return dataNew;
@adamrosloniec
adamrosloniec / gist:0b140381c2eece1f793a367f814ce709
Created July 17, 2019 21:55
ES6 - Extract unique characters from string
dataOld = 'asdasdasdasdasdasdasda';
const dataNew = [...new Set(dataOld)].join('')
// 'asd'
@adamrosloniec
adamrosloniec / remove-special-characters.js
Last active July 17, 2019 22:51
Node - Remove all special characters from file (.txt, text file, etc)
var fs = require('fs');
fs.readFile("file-with-emoji.txt", "utf-8", (err, data) => {
var dataOld = data
var dataNew = dataOld.replace(/[^0123456789aąbcćdeęfghijklłmnńoópqrsśtuvwxyzźżAĄBCĆDEĘFGHIJKLŁMNŃOÓPQRSŚTUVWXYZŹŻ\ \!\"\#\$\%\&\'\(\)\+\,\.\/\:\;\<\=\>\?\@\[\]\_\`\{\|\}\–\—\‘\’\‚\“\”\„\…\-]/g, '');
fs.writeFile("file-without-emoji.txt", dataNew, (err) => {
console.log("Successfully Written to File.");
});
})
@adamrosloniec
adamrosloniec / gist:eff0f9b519d534dd920d42dc5dc92493
Created July 13, 2019 08:42
MAMP - MySQL from Command Line
/Applications/MAMP/Library/bin/mysql -uroot -proot
@adamrosloniec
adamrosloniec / gist:230c5346e7a7505429b0d47de8f4291c
Created July 11, 2019 05:26
WordPress - Update admin in SQL, without email notification
function update_admin_email() {
global $wpdb;
$wpdb->query("UPDATE `wp_options` SET `option_value` = 'admin@test.local' WHERE `option_name` = 'admin_email'");
}
add_action('init', 'update_admin_email');
@adamrosloniec
adamrosloniec / gist:7cbd29554c34b37d1d6251bcb52afb35
Created July 10, 2019 00:23
JavaScript - In Object - Find Keys with same prefix
var obj = {
online_rate_1: "$5.00",
online_rate_2: "$22.00",
online_rate_3: "$44.00",
rate_1: "$9.00",
rate_2: "$18.00",
rate_3: "$30.00",
rate_description: "<p>Some description text</p>",
time_period_1: "0 - 0.5 Hours",
time_period_2: "0.5 - 1 Hours",
@adamrosloniec
adamrosloniec / change-file-date-modified-to-date-taken-created.sh
Last active October 5, 2019 23:50
Command Line Bash - Change file date modified to date taken/created - For each file in directory - Linux/Mac
# Command Line Bash - Change file date modified to date taken/created - For each file in directory - Linux/Mac
# 1. Best method, find file with .jpg extension, and do function:
find . -iname \*.jpg -exec sh -c 'for f in "$@";do m="$(GetFileInfo -d "$f")";SetFile -m "$m" -d "$m" "$f";done' sh {} +
# 2. My old method - Example with all files in current directory:
for f in $(ls .);do touch -t $(date -r $(stat -f%B $f) +%Y%m%d%H%M) $f;done
# 3. My old method - Example with all files in specific directory:
# specific directory is for example:
@adamrosloniec
adamrosloniec / gist:a70efb7c7c6378a54cf9019df8c6133a
Created June 30, 2019 22:13
MacOS - Change file - Created date and modification date
// without seconds (YEAR, MONTH, DAY, HOUR, MIN):
touch -t 201904191556 image.jpg
// with seconds (YEAR, MONTH, DAY, HOUR, MIN.SECONDS):
touch -t 201904191556.12 image.jpg
@adamrosloniec
adamrosloniec / gist:6bb75b4313453d8d3232cbd0301fa675
Created May 18, 2019 01:15
Easiest way to add fade in effect after Page Load
// Add in head section - for fastest loading, before scripts and styles.
<style type="text/css">body{overflow:hidden;pointer-events:none;opacity:0;transition:opacity 2s;-webkit-transition:opacity 2s;}</style>
<script type="text/javascript">window.onload=function(){document.body.setAttribute("style","overflow:initial;opacity:1;pointer-events:initial;");}</script>
@adamrosloniec
adamrosloniec / gist:e295c9bc2fbd7b78e1be0037e92684fb
Created May 13, 2019 01:41
GIT - Show list of changed files in 4 last commits (ex. in 4 last commits)
// show changed files in only last one commit:
git diff --name-only HEAD~1..HEAD
// show changed files in 4 last commits:
git diff --name-only HEAD~4..HEAD