Skip to content

Instantly share code, notes, and snippets.

Avatar
🔰
Open-Source enthusiast

PatricNox PatricNox

🔰
Open-Source enthusiast
View GitHub Profile
@PatricNox
PatricNox / db-init.sh
Created Feb 11, 2020
Database Init script for Wordpress sites through Docker
View db-init.sh
#!/bin/sh
#
# This file needs to be executed once a new database is imported.
# What this does, is updating database to tell wordpress that the site should
# be runned on localhost.
#
## Supress warning.
export MYSQL_PWD=wordpress
@PatricNox
PatricNox / init.sh
Created Feb 11, 2020
Init script for Wordpress sites through Docker
View init.sh
#!/bin/sh
#
# This file needs to be executed once a new file system is imported.
# What this does, is updating project settings to have localhost as root.
#
# Dev settings & htaccess.
if [ -f "src/wp-config.php" ]; then
rm src/wp-config.php
@PatricNox
PatricNox / dev-bash_profile
Last active Jun 1, 2020
Update my dev config to the latest
View dev-bash_profile
export PATH=$PATH:/Users/lia/.npm-packages/bin
source $(brew --prefix nvm)/nvm.sh
## General shorthands.
alias update='source ~/.bashrc'
alias sshkey="cat ~/.ssh/id_rsa.pub | pbcopy"
alias httpdconf="code /usr/local/etc/httpd/httpd.conf"
alias ll='ls -la'
## Local.
@PatricNox
PatricNox / input_type_time-calculate-difference.js
Last active Jan 16, 2020
Calculate the difference between two html time field types
View input_type_time-calculate-difference.js
<!-- HTML fields -->
<input type="time" class="field--time-period-from">
<input type="time" class="field--time-period-to">
<input type="text" class="field--time-difference" disabled>
<script>
// Get the inputs.
let timeField = document.querySelector('.field--time-difference');
let from = document.querySelector('.field--time-period-from').value;
let to = document.querySelector('.field--time-period-to').value;
@PatricNox
PatricNox / change-author-of-pushed-commits.sh
Last active Oct 7, 2020
Change author of pushed commits in git
View change-author-of-pushed-commits.sh
git filter-branch -f --env-filter '
OLD_EMAIL="patric.johansson@ucsit.se"
CORRECT_NAME="PatricNox"
CORRECT_EMAIL="hello@PatricNox.info"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]
@PatricNox
PatricNox / _match_array_content.php
Last active Sep 12, 2019
Find identical content between two arrays.
View _match_array_content.php
<?php
/**
* Find identical content between two arrays.
*
*
* @param Array $first_array
* @param Array $second_array
* @return Array
**/
View clear_vendor_node_modules.sh
#!/bin/sh
#####
# These two shell commands goes through all subfolders in the current standing folder
# and deletes vendor & node_module folder.
####
# Recursively find and delete all folders called: "node_modules"
### Used by npm.
find . -name "node_modules" -type d -prune -exec rm -rf '{}' +
@PatricNox
PatricNox / sunrise_sunset.php
Created Sep 3, 2019
PHP - Get the sunrise/sunset time with accuracy
View sunrise_sunset.php
<?php
/*
* Calculate the sunrise/sunset time for Gothenburg, Sweden
*
* Latitude: 57.696991
* Longitude: 11.986500)
*/
$date_sun_info = date_sun_info(strtotime("2019-09-03"), 57.696991, 11.986500);
@PatricNox
PatricNox / PHP: Remove last part of String
Created Aug 9, 2019
PHP function that removes the last part of a string.
View PHP: Remove last part of String
/**
* Remove the last part of a string.
*
* This function removes the last part of a string, conditioned on spaces
* inbetween the parts. Like words, in a sentence.
*
* @param String $string The string.
**/
function str_remove_lastpart($string) {
$string_parts = explode(' ',$string);
@PatricNox
PatricNox / boss_noth.cpp
Created Jun 21, 2019
TrinityCore 3.3.5 Naxxramas BossScript
View boss_noth.cpp
/*
* Copyright (C) 2008-2017 TrinityCore <http://www.trinitycore.org/>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or