Skip to content

Instantly share code, notes, and snippets.

View zgulde's full-sized avatar

Zach Gulde zgulde

View GitHub Profile
<?php
// takes a start and end date as a string and returns the number of days
// between them
function diffInDays($start, $end)
{
$start = new DateTime($start);
$end = new DateTime($end);
return date_diff($start, $end)->days;
}

Help! My codeup.dev isn't working!

In general there are several things to look at if you cannot access your files through codeup.dev:

  1. Is your vagrant server running?

    I.e. what is the output of this code

cd ~/vagrant-lamp

Using Git

A common way to manage the versions of your files and content is to name files with increasing levels of description. Example: Resume.pdf, Resume_Final.pdf, Resume_Final_Monday.pdf, Resume_FINAL_to_print.pdf, and Resume_print_before_interview.pdf vs. a permanent record with a time machine that can enter paralell dimensions

Git, the Big Picture

  • Git is a permanent record.
  • Git is a time machine that allows us to travel through that permanent record.
  • Git also allows us to travel into parallel universes (branches)
  • GitHub is a service that hosts remote repositories.
@zgulde
zgulde / js-array-methods.md
Last active April 12, 2017 20:11
common javascript array manipulation methods

Array Methods

name modifies the original? return value description
push, unshift yes the length of the new array add element(s) to an array
pop, shift yes the element removed remove an element from the beginning or end of an array
reverse yes the new array reverses the array
sort yes the new array sort the array
splice yes an array of deleted items delete an
#!/bin/bash
# will disable or enable a touchpad device
TOUCHPAD_ID="$(xinput list | grep -oi 'touchpad\s*id=[0-9]\{1,\}' | grep -o '[0-9]\{1,\}')"
ENABLED="$(xinput list-props $TOUCHPAD_ID | grep -i 'device enabled' | grep -o '[0-9]$')"
if [ $ENABLED -eq 1 ]; then
xinput disable $TOUCHPAD_ID
echo "Touchpad disabled."

Echo shorthand

<?php echo $variable ?>

is the same as

= $variable ?&gt;

Remove a file from git history

Note: you will need a clean working directory to do this.

We will be rewriting history! This will entirely remove the commit from history

You should probably only do this if you really need to remove a file entirely from history. For example if the file you added is too large and GitHub won't accept it. If you are just trying to undo what a commit has done, there are better ways to do it without modifying history, check out git revert.

We are assuming that the problematic file was added in one commit and not modified since.

MySQL General error: 1215 Cannot add foreign key constraint

This will give you more details

echo 'show engine innodb status\G' | mysql -u homestead -p | grep -C10 -i latest

s/homestead/your username/

fallocate -l 1G /swap
mkswap /swap
echo "/swap none swap sw 0 0" >> /etc/fstab
swapon -ae