Skip to content

Instantly share code, notes, and snippets.

@BeFiveINFO
BeFiveINFO / get_curl_output_by_url
Last active August 29, 2015 14:17
Pass URL and it returns html by curl
<?php
/**
* This curl function might be useful when get_file_contents() cannot be used for any reasons.
* E.g. when you need to pass user agent etc.
*
* Todo: return array with response code & the content
*/
function get_curl_output_by_url ( $_curl_url ) {
$ch = curl_init();
$useragent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";
@BeFiveINFO
BeFiveINFO / gist:be2b8c23aa387dd06f41
Created September 13, 2015 12:02
Wordpress 4.3 get_file_data snippet
I wanted to analyse this function for my use. ... I want to make a javascript function (for gruntjs) to get version number oftheme.
/**
* Retrieve metadata from a file.
*
* Searches for metadata in the first 8kiB of a file, such as a plugin or theme.
* Each piece of metadata must be on its own line. Fields can not span multiple
* lines, the value will get cut at the end of the first line.
*
* If the file data is not within that first 8kiB, then the author should correct
@BeFiveINFO
BeFiveINFO / gist:b80c0bc5078107332906
Created September 13, 2015 13:49
Javascript time conversion functions
/*
* Calculates the Twitter time since the tweet was created
* Based on http://www.jquery4u.com/api-calls/calculate-twitter-time-tweet-javascript/
* @param obj with datetime (e.g. git time etc). and limitSwitch (optional) in minute --- any dates beyond that will be in date in string
* @return time since in html
*/
var calculateSince = function ( _parameter ) {
var _datetime = _parameter.dateTime.replace(/\-/g,'/');
var _limitSwitch = (_parameter.limitSwitch) ? _parameter.limitSwitch : 4320; /* optional */
@BeFiveINFO
BeFiveINFO / chrome-admin-menu-fix.php
Last active July 8, 2017 02:58
WordPress Chrome Admin Menu Fix
<?php
/*
Plugin Name: Chrome Admin Menu Fix
Description: This plugin fixes the WordPress admin menu which is caused by the latest version of Google Chrome (45).
Version: 1.1
Author: Luke Williamson (note: this is a modified vesion)
Author URI: http://lukewilliamson.com.au
License: GPLv2
*/
// ommitted
In terminal:
If you have a new local github repo without any file added, do:
$ jekyll new ./
It installs all the default jekyll files in the directory.
To launch a local server:
@BeFiveINFO
BeFiveINFO / gist:4b54eb02e7533edf5036
Created December 24, 2015 09:20
Table text content scraper idea
/*
copy and paste into the console of browser
*/
var _listArray = [];
jQuery('tbody tr[role=row]').each(function (i) {
var $_current = $(this);
var _name = $_current.find(':nth-child(1) a').text();
var _email = $_current.find(':nth-child(2) a').text();
_listArray.push({
name: _name,
#!/usr/bin/env bash
# requires geoiplookup, do "brew install geoip"
# and brew install geoiplookup
# this is how to extract ip addresses and the count of occurances
# egrep -o '[0-9]+(\.[0-9]+){3}' < accesslog.txt | sort | uniq -c | sort -nr > access.txt
# specify the output access.txt as an argument,
if [ $# -ne 1 ]; then
echo "$# argument specified" 1>&2
echo "this script requires 1 argument" 1>&2
exit 1
@BeFiveINFO
BeFiveINFO / gist:23407e981e3120c22457
Created March 17, 2016 09:50
Using get_theme_mod() so that it works in Customizer live preview
<?php
// for example, in your functions.php or anywhere in your theme
// Use wp_loaded action hook
add_action( 'wp_loaded', 'get_my_options' );
function get_my_options() {
define('MY_OPTION',get_theme_mod('my_option', FALSE));
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo