Skip to content

Instantly share code, notes, and snippets.

View hitautodestruct's full-sized avatar

Yotam hitautodestruct

View GitHub Profile
@hitautodestruct
hitautodestruct / vhosts.conf
Created March 25, 2015 11:35
Definition for apache virtual host dev setup.
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "/Users/username/code/wp"
ServerName wp.website.com
ServerAlias wp.website.com
ServerAlias wp-website.*.xip.io
ErrorLog "logs/error_log_website.log"
<Directory "/Users/username/code/wp/">
Options Indexes FollowSymLinks Includes
AllowOverride All
@hitautodestruct
hitautodestruct / conf.md
Last active August 29, 2015 14:18
How to configure MAMP on OSX to allow for vHosts file and multiple domains
  1. Open up httpd.conf (/Applications/MAMP/conf/apache/httpd.conf)

  2. Uncomment the line under Virtual Hosts:

    Looks like this:

    # Virtual hosts
    #Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
    

    Should look like this:

A good "ready-to-use tool" option could be http-server:

npm install http-server -g

To use it:

cd D:\Folder
http-server

Or, like this:

@hitautodestruct
hitautodestruct / storage.js
Created November 15, 2015 12:03
AngularJS service for getting and setting data
app.factory('storage', function() {
var store = {}
function set(key, data) {
store = data;
localStorage.setItem( key, JSON.stringify( data ) );
}
function get( key ) {
@hitautodestruct
hitautodestruct / wordpress-ajax.php
Last active November 19, 2015 11:48
The basics of creating an internal wordpress ajax request.
<?php
// Inside functions.php
function get_category_posts(){
$nonce = $_POST['nonce'];
// check to see if the submitted nonce matches with the
// generated nonce we created earlier
if ( ! wp_verify_nonce( $nonce, 'my-nonce' ) )
@hitautodestruct
hitautodestruct / html_entity_escape.js
Created May 6, 2013 11:48
This function converts special chars into html enteties. This is a nodejs module form this answer: http://stackoverflow.com/a/1354715/414385 on StackOverflow. Usage: var ee = require('./html_entity_escape'); ee.convert('Special § £ Chars'); // Special &sect; &pound; Chars
module.exports = {
convert: function( text ){
// all HTML4 entities as defined here: http://www.w3.org/TR/html4/sgml/entities.html
// added: amp, lt, gt, quot and apos
this.entityTable = {
34 : 'quot',
38 : 'amp',
39 : 'apos',
@hitautodestruct
hitautodestruct / flat_wp_nav_menu.php
Created May 13, 2013 11:36
A short wordpress menu generator with only top level links. No hierarchy.
<?php
$menu_name = 'sidebar_nav';
$locations = get_nav_menu_locations();
$menu = wp_get_nav_menu_object( $locations[ $menu_name ] );
$menuitems = wp_get_nav_menu_items( $menu->term_id, array( 'order' => 'DESC' ) );
?>
<ul class="side-menu">
<?php
@hitautodestruct
hitautodestruct / console_log.php
Created August 27, 2013 08:15
Better implementation of a `var_dump` function for web debugging.
function console_log ( $output ) {
echo '<script>';
echo 'console.log('. json_encode( $output ) .');';
echo '</script>';
}
@hitautodestruct
hitautodestruct / fb-profile-picture.html
Created October 7, 2013 08:28
Get any profile picture (by ID) from facebook.
<img src="http://graph.facebook.com/4/picture?type=large" alt="Mark Zukerberg's Profile Picture">
@hitautodestruct
hitautodestruct / btn-directive.js
Created October 8, 2013 10:10
Angularjs directive for simplifying bootstrap buttons. Removes the need to add a `class="btn btn-lg btn-success"` etc. http://jsbin.com/ibinASA/1/edit
var app = angular.module('boostrapButton', []);
app.directive('btn', function () {
return function ( scope, element, attrs ) {
var classes = attrs.btn.split(' ');
classes.unshift('btn');