Skip to content

Instantly share code, notes, and snippets.

View SabrinaMarkon's full-sized avatar
🐦

Sabrina Markon SabrinaMarkon

🐦
  • VML
  • Calgary, Alberta
View GitHub Profile
@SabrinaMarkon
SabrinaMarkon / laravel5.2-eloquent-orderBy-muliple-columns.txt
Last active August 22, 2016 18:59
Sabrina Notes - Laravel 5.2 - Eloquent - How to order database SELECT results by multiple columns
Laravel 5.2 - Eloquent - How to order database SELECT results by multiple columns
---------------------------------------------------------------------------------
Chain together using orderBy with the columns being sorted in the order they are chained, as in the example line below:
$contents = ModelName::orderBy('columnA', 'asc')->orderBy('columnB', 'desc')->get();
If $contents is returned to the view now, all rows of the table will be sorted first according to the ascending values of
columnA, followed by a second sort of the desc values of column B.
@SabrinaMarkon
SabrinaMarkon / laravel5.2-validator-customize-errors.txt
Last active August 22, 2016 19:24
Sabrina Notes - Laravel 5.2 - Validator: How to customize the error messages produced by the validator
Sabrina Notes - Laravel 5.2 - Validator: How to customize the error messages produced by the validator
-------------------------------------------------------------------------------------------------------
1) Edit /resources/lang/en/validation.php
2) In the first section, called 'Validation Language Lines', you can edit the default error messages for existing validation rules:
Example:
One default error message is:
@SabrinaMarkon
SabrinaMarkon / laravel5.2-validator-check-if-errors-dont-show.txt
Last active August 26, 2016 23:00
Sabrina Notes - Laravel 5.2 - Validator: Things to check when you know there should be an error returned, but it is empty
Sabrina Notes - Laravel 5.2 - Validator: Things to check when you know there should be an error returned,
but it is empty. For instance, if you use Bootstrap, your error bar might show, but the words won't show
in it.
----------------------------------------------------------------------------------------------------------
1) My Mistake:
@if (count($errors) > 0)
<div class="alert alert-danger">
<ul>
@SabrinaMarkon
SabrinaMarkon / gist:0da6cf5304acb90f304d870bc64ff5b3
Created December 22, 2016 12:04
php-force-refresh-of-image-to-ensure-user-sees-most-recent-version.txt
If an application allows users to edit images, for example, once the image file is saved and the user returned to the page
showing their images (such as in the banner maker app), the behavior by default is that a cached version of an image is shown until
the user manually refreshes the page. This results in confusion because the person just edited the image and therefore expects those
changes to show right away.
To solve this problem it is a simple matter of creating a random string, such as the date/time:
$today = date("YmdHis");
Then in the HTML img tags, add ?$today to the end of the image src attribute.
@SabrinaMarkon
SabrinaMarkon / .htaccess
Created January 2, 2017 10:34 — forked from ScottPhillips/.htaccess
Common .htaccess Redirects
#301 Redirects for .htaccess
#Redirect a single page:
Redirect 301 /pagename.php http://www.domain.com/pagename.html
#Redirect an entire site:
Redirect 301 / http://www.domain.com/
#Redirect an entire site to a sub folder
Redirect 301 / http://www.domain.com/subfolder/
@SabrinaMarkon
SabrinaMarkon / algorithm-binary-how-many-ones-in-a-row.php
Last active January 11, 2017 19:03
Sabrina Markon - Algorithms - For a given integer (from STDIN), convert to binary then find out the greatest number of 1's in a row in the binary number.
<?php
$handle = fopen ("php://stdin","r");
fscanf($handle,"%d",$n);
function addToStack($x, &$stack) {
$remainder = $x % 2;
$nextx = ($x - $remainder)/2;
array_unshift($stack, $remainder);
if ($nextx >= 1) {
addToStack($nextx, $stack);
@SabrinaMarkon
SabrinaMarkon / algorithm-using-arguments-and-filter-to-remove-array-elements.txt
Last active January 15, 2017 22:01
Sabrina Markon - Algorithms - Array with argument 0 being a sub array. We want to use the other unknown number of elements as arguments to remove their values from the sub array.
Seek and Destroy
----------------
You will be provided with an initial array (the first argument in the destroyer function), followed by one or more arguments.
Remove all elements from the initial array that are of the same value as these arguments.
function destroyer(arr) {
// Remove all the values
// arr array is the first element in the destroyer function, while the other arguments
// are in the arguments array:
@SabrinaMarkon
SabrinaMarkon / algorithm-add-element-to-array-then-sort-and-return-first-index-of-the-value-of-the-added-element.txt
Created January 15, 2017 22:22
Sabrina Markon - Algorithms - We add a new integer to an existing array of integers, sort it using compare, then return the index of the first occurrence of the new element.
Sabrina: Notice how sort() includes a compare function. Since sort sorts by alphabetical order, sorting numbers tends to be WRONG.
The string "25" for example is GREATER THAN the string "100". So we compare with function(a,b) { return a-b; } to sort NUMBERS in
ASCENDING ORDER. (for descending order use return b-a instead).
Return the lowest index at which a value (second argument) should be inserted into an array (first argument) once it has been sorted.
The returned value should be a number.
For example, getIndexToIns([1,2,3,4], 1.5) should return 1 because it is greater than 1 (index 0), but less than 2 (index 1).
Likewise, getIndexToIns([20,3,5], 19) should return 2 because once the array has been sorted it will look like [3,5,20] and
@SabrinaMarkon
SabrinaMarkon / algorithm-use-javascript-charCodeAt-and-String.fromCharCode-to-decode-ROT13-shifted-message.txt
Created January 17, 2017 21:50
Sabrina Markon - Algorithms - Ceasar Cipher. We are given a ROT13 string and must decode it to find the secret message.
/*
One of the simplest and most widely known ciphers is a Caesar cipher, also known as a shift cipher.
In a shift cipher the meanings of the letters are shifted by some set amount.
A common modern use is the ROT13 cipher, where the values of the letters are shifted by 13 places.
Thus 'A' ↔ 'N', 'B' ↔ 'O' and so on.
Write a function which takes a ROT13 encoded string as input and returns a decoded string.
All letters will be uppercase.
@SabrinaMarkon
SabrinaMarkon / how-to-access-in-blade-views.txt
Last active February 10, 2017 08:08
Sabrina Notes - Laravel 5.3 - Make site settings from database model available to all controllers and views using a custom service provider.
Use in your blade templates like:
{{ $your_variable_name }}
OR:
{{ $settings['your_variable_name'] }}