Skip to content

Instantly share code, notes, and snippets.

@alenabdula
alenabdula / get_post_top_ancestor_id.php
Created August 6, 2015 18:11
Gets the id of the topmost ancestor of the current page and returns the current page's id if there is no parent.
<?php
/**
* --------------------------------------------------------
* Gets the id of the topmost ancestor of the current page.
* Returns the current page's id if there is no parent.
* @uses Object $post
* @return Int
* --------------------------------------------------------
*/
function get_post_top_ancestor_id () {
@alenabdula
alenabdula / nginx.conf
Created October 29, 2015 16:58
Nginx: Serve WebP image instead of JPEG or PNG files, if browser supports it.
# Check to see if .webp image is supported in the browser
# Serve .webp image, if avaiable, instead of .jpeg / .png
location / {
if ( $http_accept ~ "image/webp" ) {
rewrite (.+)\.(jpe?g|png)$ /$1.webp;
}
}
@alenabdula
alenabdula / service-worker.html
Last active October 30, 2015 13:11
Service Worker
<script>
if ( 'serviceWorker' in navigator ) {
navigator.serviceWorker.register('/service-worker.js', { scope: '/' })
.then(function(registration) {
console.log("Service Worker Registered");
});
navigator.serviceWorker.ready.then(function(registration) {
console.log("Service Worker Ready");
});
}
@alenabdula
alenabdula / beautified-js-code.js
Last active November 9, 2015 16:34
Hacked WordPress footer.php file
function(e, t) {
function l(e, n, r) {
if (r === t && e.nodeType === 1) {
var i = "data-" + n.replace(f, "$1-$2").toLowerCase();
r = e.getAttribute(i);
if (typeof r == "string") {
try {
r = r === "true" ? !0 : r === "false" ? !1 : r === "null" ? null : s.isNaN(r) ? a.test(r) ? s.parseJSON(r) : r : parseFloat(r)
} catch (o) {}
s.data(e, n, r)
hostname = "localhost.dev"
boxname = "VBlocalhost"
server_ip = "192.168.22.10"
server_cpus = "1"
server_memory = "512" # in MB
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.hostname = hostname
config.vm.network :private_network, ip: server_ip
#
# DigitalOcean Ubuntu Droplet
# Random things I encountered when working
# with DigitalOcean's Ubuntu VM Instance
# and some one liners like...
# Restart Server
sudo shutdown -r now
# Update Individual Package
function Pythagorean() {}
Pythagorean.prototype.calculate = function(obj) {
if (Object.keys(obj).length > 3 ) {
throw 'This function accepts object with maximum of 3 properties';
}
if ( typeof obj.c === 'object' ) {
return Math.sqrt(Math.pow(obj.a,2) + Math.pow(obj.b,2));
}
else {
if ( obj.c <= obj.a || obj.c <= obj.b ) {
@alenabdula
alenabdula / timber-custom-headers.php
Created December 11, 2015 18:24
Sets proper headers for RSS Feeds using Timber Library and Twig Templating Engine
<?php
/**
* Sets proper headers for RSS Feeds using Timber Library and Twig Templating Engine
* Fallbacks:
* 1. application/rss+xml,
* 2. application/rdf+xml,
* 3. application/atom+xml,
* 4. application/xml,
* 5. text/xml
*/
@alenabdula
alenabdula / PHPUnitTestSnippet.sublime-snippet
Last active December 20, 2015 14:05
Sublime Text snippet to automate process of creating a PHPUnit test case
<snippet>
<content>
<![CDATA[
/** @test */
function ${1/\s/_/g}()
{
${0:// ${1:type method name with spaces when done press tab}}
}
]]>
</content>