Skip to content

Instantly share code, notes, and snippets.

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 ) {
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
@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)
@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 / 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 / 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 () {
<?php
add_action( 'init', 'block_access_to_wp_dashboard_init' );
/**
*
*/
function block_access_to_wp_dashboard_init() {
if ( is_admin() && ! current_user_can( 'edit_users' ) && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
wp_redirect( home_url() );
@alenabdula
alenabdula / .htaccess
Created May 28, 2015 15:49
Custom .htaccess file
# ----------------------------------------------------------------------
# | Application Redirects
# ----------------------------------------------------------------------
Redirect 301 /old http://www.example.com/new
# ----------------------------------------------------------------------
# | Cross-origin images
# ----------------------------------------------------------------------
<IfModule mod_setenvif.c>
<IfModule mod_headers.c>