Skip to content

Instantly share code, notes, and snippets.

View scodx's full-sized avatar
🏠
Working from home

Oscar Sánchez scodx

🏠
Working from home
View GitHub Profile
sudo scutil --set ComputerName "newname"
sudo scutil --set LocalHostName "newname"
sudo scutil --set HostName "newname"
@scodx
scodx / PHP Architect - Scrapping publications.js
Last active April 6, 2017 00:24
little jQuery script to get the PHP Architect url publications to download (given you have an active subscription)
var publications = [];
jQuery(".container .year").each(function(){
var id = jQuery(this).attr("id"),
year = id.split("-").pop(),
monthName = "";
jQuery(this).find(".item").each(function(monthNum, monthContainer){
jQuery(monthContainer).find("a").each(function(index, el){
@scodx
scodx / git-log-pretty.sh
Created April 24, 2017 15:52
Git Log Pretty Format
lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%C(bold blue)<%an>%Creset' --abbrev-commit
@scodx
scodx / add-zeroes.md
Last active October 11, 2019 20:32
Adding 0's to a string when is lower than 10 in PHP and JS

PHP

$n = sprintf("%04d", $n)

JS

var n = ('00'+'09').slice(-2);
set global sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
set session sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
SET global log_output = 'FILE';
SET global general_log_file='/path/to/mysql_general.log';
SET global general_log = 1;
# ERROR: sudo: no tty present and no askpass program specified
sudo visudo
# or edit #includedir /etc/sudoers.d
username ALL = NOPASSWD: /fullpath/to/command, /fullpath/to/othercommand
# All applications:
# username ALL=(ALL) NOPASSWD: ALL

Undo a commit and redo

git reset HEAD~

This leaves your working tree (the state of your files on disk) unchanged but undoes the commit and leaves the changes you committed unstaged (so they'll appear as "Changes not staged for commit" in git status, and you'll need to add them again before committing). If you only want to add more changes to the previous commit, or change the commit message1, you could use git reset --soft HEAD~ instead, which is like git reset HEAD~ but leaves your existing changes staged.

@scodx
scodx / clear-form.js
Created October 28, 2017 13:59
Clears a form (like reset). Be aware for input types that clear data used for the app logic, like hidden.
function clearForm(myFormElement) {
var elements = myFormElement.elements;
myFormElement.reset();
for(i=0; i<elements.length; i++) {
field_type = elements[i].type.toLowerCase();
@scodx
scodx / my.cnf
Created November 10, 2017 06:49 — forked from fragje/my.cnf
Custom my.cnf for use with MAMP. Place this file in `/Application/MAMP/conf/` and restart MAMP
# Example MySQL config file for large systems.
#
# This is for a large system with memory = 512M where the system runs mainly
# MySQL.
#
# MySQL programs look for option files in a set of
# locations which depend on the deployment platform.
# You can copy this option file to one of those
# locations. For information about these locations, see:
# http://dev.mysql.com/doc/mysql/en/option-files.html