Skip to content

Instantly share code, notes, and snippets.

View sudar's full-sized avatar

Sudar Muthu sudar

View GitHub Profile
<?php
/**
* Create a new page in WordPress
*/
function create_page($title, $content = '', $parent = 0, $page_template = '', $menu_order = 0) {
$args = array(
'post_title' => $title,
'post_content' => $content,
'post_parent' => $parent,
'menu_order' => $menu_order,
@sudar
sudar / empty-lines-count.sh
Created March 28, 2013 02:45
Grep command to find empty and non-empty lines in a file. Explanation at http://sudarmuthu.com/blog/count-the-number-of-empty-lines-in-a-file-using-grep
grep -cv -P '\S' filename
@sudar
sudar / arrays.txt
Last active January 30, 2016 11:59
Awk command to remove duplicate lines, based on a field. Explanation at http://sudarmuthu.com/blog/remove-duplicate-lines-based-on-a-field
# Before starting
x = {}
# After line 1
x = {
CTO => 1
}
# After line 2
x = {
@sudar
sudar / error.log
Last active December 13, 2015 21:08
Parse apache error log and get the list of images that are not found. More details at http://sudarmuthu.com/blog/parse-apache-error-log-and-list-down-all-missing-images
[Tue Dec 18 06:32:50 2012] [error] [client 10.66.180.194] File does not exist: /path/to/file/that/is/missing
@sudar
sudar / wp-increase-timeout.php
Created February 13, 2013 15:54
Increase the curl timeout in WordPress
<?php
Copied from http://fatlabmusic.com/blog/2009/08/12/how-to-fix-wp-http-error-name-lookup-timed-out/
//adjustments to wp-includes/http.php timeout values to workaround slow server responses
add_filter('http_request_args', 'bal_http_request_args', 100, 1);
function bal_http_request_args($r) //called on line 237
{
$r['timeout'] = 15;
return $r;
}
/**
* Retrieve posts ids given their title.
* Use this function if there are more than one post with the same title.
*/
function get_multiple_posts_by_title($title) {
global $wpdb;
$posts_ids = array();
$posts = $wpdb->get_results( $wpdb->prepare( “SELECT ID FROM $wpdb->posts WHERE post_title = %s AND post_type=’post_type’”, $title), OBJECT );
foreach ($posts as $post) {
@sudar
sudar / max3421e_constants.h
Created September 7, 2012 15:13
Patch to make Sparkfun USB Host shield work with USH Host Shield library. More details at http://hardwarefun.com/tutorials/using-usb-host-shield-with-arduino
#define MAX_GPX 7
#define MAX_RESET 8
@sudar
sudar / url-encode.c
Created August 20, 2012 14:59
URLEncoding in C
int c;
char *hex = "0123456789abcdef";
while( (c = getchar()) != EOF ){
if( ('a' <= c && c <= 'z')
|| ('A' <= c && c <= 'Z')
|| ('0' <= c && c <= '9') ){
putchar(c);
} else {
putchar('%');
@sudar
sudar / gist:3321846
Created August 11, 2012 06:43
YQL queries used for my talk about Flickr
// Select Photos that have the term Bike in them
select * from flickr.photos.search where text="Bike" and api_key="API_KEY" limit 10
// Get info about a particular photo
select * from flickr.photos.info where photo_id=2439864402 and api_key="API_KEY"
// Get the url of the photo with id
select title, urls.url from flickr.photos.info where photo_id = '7751003932' and api_key = "API_KEY"
// Do a subquery to get the urls of all photos that have the term Bike in them
{
"query" : {
"count" : 1,
"created" : "2012-08-04T14:46:03Z",
"lang" : "en-US",
"results" : {
"item" : {
"title" : "Handling FTP usernames with @ in them"
}
}