Skip to content

Instantly share code, notes, and snippets.

View ChrisBuchholz's full-sized avatar

Christoffer Buchholz ChrisBuchholz

View GitHub Profile
<?php
// The slow, although default way of doing fibonacci ---------------------------
function _fibs($n)
{
if ($n < 2)
return $n;
else
return _fibs($n-1) + _fibs($n-2);
<?php
class Synthesization {
private function signatureIsGetter($signature) {
if (preg_match('/^get/', $signature))
return true;
return false;
}
// data
var nums = [1, 2, 3, 4, 5, 6, 7, 8];
// What you would do if you did not have a functional mindset
var evens = [];
for (var i = 0; i < nums.length; ++i) {
if (nums[i] % 2 === 0) {
evens.push(nums[i]);
<?php
function pluckWith($key, $array) {
return function($value) use ($key, $array) {
$matches = [];
foreach ($array as $k => $v)
if (array_key_exists($key, $v) && $v[$key] == $value)
array_push($matches, $array[$k]);
return $matches;
};
// Library method --------------------------------------------------------------
var pluckWith = function(k, a) {
return function(v) {
var res = [];
for (var i = 0; i < a.length; i++)
if (a[i].hasOwnProperty(k) && a[i][k] === v)
res.push(a[i]);
return res;
};
<script type="text/x-handlebars" data-template-name="sometemplate">
<script src="jquery.js"></script>
</script>
<script type="text/x-handlebars" data-template-name="sometemplate">
<script src="jquery.js"></script>
</script>
<script type="text/x-handlebars" data-template-name="sometemplate">
<script src="jquery.js"></script>
</script>
safeInit :: [a] -> [a]
safeInit (x:xs)
| null xs = []
| otherwise = x : safeInit xs
$query = new WP_Query(array(
'post_type' => 'music',
'posts_per_page' => 5
));
while($query->have_posts()) {
echo "post";
}