This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function makeNonce(length) { | |
let nonce = ""; | |
let possible = "0123456789"; | |
for (let i = 0; i < length; i++) { | |
nonce += possible.charAt(Math.floor(Math.random() * possible.length)); | |
} | |
return nonce; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Fisher-Yates-Durstenfeld shuffle | |
// https://stackoverflow.com/questions/3718282/javascript-shuffling-objects-inside-an-object-randomize | |
function shuffle(sourceArray) { | |
for (var i = 0; i < sourceArray.length - 1; i++) { | |
var j = i + Math.floor(Math.random() * (sourceArray.length - i)); | |
var temp = sourceArray[j]; | |
sourceArray[j] = sourceArray[i]; | |
sourceArray[i] = temp; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT p.post_date, COUNT(*) FROM wp_posts p | |
JOIN wp_term_relationships tr | |
ON p.ID = tr.object_id | |
WHERE tr.term_taxonomy_id = 15996 | |
AND p.post_status = "publish" | |
AND p.post_type = "post" | |
AND p.post_date > "2017-02-06" | |
GROUP BY YEAR(p.post_date), MONTH(p.post_date), DAY(p.post_date) | |
ORDER BY p.post_date ASC |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function returnRedirectedUrl($url) | |
{ | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_HEADER, true); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); | |
$a = curl_exec($ch); | |
if(preg_match('#Location: (.*)#', $a, $r)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<style> | |
/* BASE RULES */ | |
html, body { | |
width: 100%; | |
height: 100%; | |
background-color: #ccccff; | |
} | |
div { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Flatten array of PDO results into a single dimension. | |
* Note: This is only useful for a PDO query returning a single column (you probably don't want to do this otherwise). | |
* | |
* @param array $arrayToFlatten | |
* @return array | |
*/ | |
public function flattenArray($arrayToFlatten, $key) | |
{ | |
// Set up array. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Pretend someObject is already defined and populated | |
const someData = {}; | |
for (var i = 0; i < someObject.length; i++) { | |
// Add object data to array. | |
someData[i] = {}; | |
someData[i].itemName = someObject[i].itemName; | |
someData[i].anotherName = someObject[i].anotherName; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var s = document.createElement('script'); | |
var scriptPath = 'https://www.someurl.com/example.js'; | |
s.setAttribute('src', scriptPath); | |
document.getElementsByTagName('head')[0].appendChild(s); |