Skip to content

Instantly share code, notes, and snippets.

@levymetal
levymetal / functions.php
Last active November 1, 2022 02:34
Custom Wordpress function which displays a list of child pages from a common parent, which can be called from either the parent page (displays children) or any of the child pages (displays siblings).
<?php
function my_custom_submenu() {
global $post;
$menu_items = wp_get_nav_menu_items('Menu');
$current_menu_id = null;
// get current top level menu item id
foreach ( $menu_items as $item ) {
@levymetal
levymetal / gist:5083696
Last active November 1, 2022 02:35
Example of how to call use the php twitter cache available @ https://github.com/levymetal/php-twitter-cache
$.getJSON('/resources/twitter_cache.php', function(data) {
$.each(data, function(i) {
console.log( data[i] );
// do something with tweet
});
});
@levymetal
levymetal / twitterCache.php
Last active November 1, 2022 02:36
Stand-alone version of the php twitter cache found @ https://github.com/levymetal/php-twitter-cache
<?php
error_reporting( 0 ); // don't let any php errors ruin the feed
$username = 'username';
$number_tweets = 4;
$feed = "http://api.twitter.com/1/statuses/user_timeline.json?screen_name={$username}&count={$number_tweets}&include_rts=1&callback=?";
$cache_file = dirname(__FILE__).'/cache/'.'twitter-cache';
$modified = filemtime( $cache_file );
$now = time();
@levymetal
levymetal / Gemfile
Last active November 1, 2022 02:36
Tutorial on how to create infinite scroll with Rails @ jQuery, full post @ http://christianvarga.com/blog/2013/02/simple-infinite-scroll-with-rails-and-jquery/
gem 'will_paginate', '~> 3.1.0'
@levymetal
levymetal / hosts
Last active November 1, 2022 02:36
Tutorial on how to use vhosts & MAMP, full post available at @ https://christianvarga.com/vhosts-and-mamp/
127.0.0.1 project1.localhost
127.0.0.1 project2.localhost
@levymetal
levymetal / direct.js
Last active November 1, 2022 01:22
Tutorial on how to use jQuery resize to parent plugin, full post available @ http://christianvarga.com/jquery-resize-image-to-parent-container-plugin/
$('#myImage').resizeToParent();
@levymetal
levymetal / directions.js
Last active November 1, 2022 02:38
Tutorial on how to calculate driving distance using Google maps API, full post available @ http://christianvarga.com/how-to-calculate-driving-distance-between-2-locations-with-google-maps-api/
var directionsService = new google.maps.DirectionsService();
var request = {
origin : 'Melbourne VIC', // a city, full address, landmark etc
destination : 'Sydney NSW',
travelMode : google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if ( status == google.maps.DirectionsStatus.OK ) {
@levymetal
levymetal / functions.php
Last active November 1, 2022 02:39
Similar to https://gist.github.com/levymetal/5064699, except this displays all sub-pages as well.
<?php
function my_custom_submenu() {
global $post;
$menu_items = wp_get_nav_menu_items('Menu');
$current_menu_id = 0;
// get current top level menu item id
foreach ( $menu_items as $item ) {
@levymetal
levymetal / direct_parent.php
Last active November 27, 2023 04:17
Custom Wordpress function which uses a nav walker to display a list of child pages from a common parent, which can be called from either the parent page (displays children) or any of the child pages (displays siblings). Detailed instructions available on my blog post here: http://christianvarga.com/how-to-get-submenu-items-from-a-wordpress-menu-…
<?php
wp_nav_menu( array(
'menu' => 'Menu Name',
'sub_menu' => true,
'direct_parent' => true
) );
@levymetal
levymetal / get_bearer_token.php
Last active November 1, 2022 02:40
Obtain a bearer token from Twitter, which can use used to send signed requests without the need for an oauth library.
<?php
$ch = curl_init();
//set the endpoint url
curl_setopt($ch,CURLOPT_URL, 'https://api.twitter.com/oauth2/token');
// has to be a post
curl_setopt($ch,CURLOPT_POST, true);
$data = array();
$data['grant_type'] = "client_credentials";