Skip to content

Instantly share code, notes, and snippets.

View freekrai's full-sized avatar

Roger Stringer freekrai

View GitHub Profile
@freekrai
freekrai / slugify.php
Created March 16, 2014 19:14
convert text to slugs
<?php
function slugify($text)
{
// replace non letter or digits by -
$text = preg_replace('~[^\\pL\d]+~u', '-', $text);
// trim
$text = trim($text, '-');
@freekrai
freekrai / loop.php
Created June 19, 2014 18:25
call get_thumb_url
<?php
if(function_exists('has_post_thumbnail') && has_post_thumbnail()) {
the_post_thumbnail("loop-image");
}else{
$thumb=get_thumb_url($post->post_content, 'loop-image');
if ($thumb!='') {
?>
<img src="<?php echo $thumb; ?>" alt="<?php get_the_title(); ?>" />
<?php
}
@freekrai
freekrai / functions.php
Created July 23, 2014 18:03
Grab latest images via instagram
<?php
function fetchData($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
@freekrai
freekrai / routing.php
Last active August 29, 2015 14:05
Add rewrite capabilites to PHP 5.4's built-in web server
<?php
// php -S localhost:8888 routing.php
if (preg_match('/\.(?:png|jpg|jpeg|gif|css|js)$/', $_SERVER["REQUEST_URI"])) {
return false;
} else {
include __DIR__ . '/index.php';
}

Intro

These gists will help through the installation of PHP54, MySQL, and Postgres

Pre-Requisists

This assumes that you have already installed Homebrew (http://mxcl.github.io/homebrew/)

Installation

<?php
/*
Checks if a string is base65 encoded or not already...
*/
function is_base64($str) {
if (!preg_match('~[^0-9a-zA-Z+/=]~', $str)) {
$check = str_split(base64_decode($str));
$x = 0;
foreach ($check as $char) if (ord($char) > 126) $x++;
if ($x/count($check)*100 < 30) return true;
<?php
$email = "me@example.com";
// To find your weather feed....
// * Go here: http://forecast.weather.gov/MapClick.php?lat=37.7749295&lon=-122.41941550000001#.UdpHAj7714E
// * Search for your location (upper left side of the page as of 7/7/2013)
// * Click the orange "XML" button/link (on the right hand side, beneath the first map as of the same date)
$feed = 'http://forecast.weather.gov/MapClick.php?lat=39.01000&lon=-96.28&unit=0&lg=english&FcstType=dwml';
<script src="//platform.twitter.com/widgets.js"></script>
<script>
var tweet = {
url: "", // url to share
via: "", // omit @, twitter username
text: "", // tweet text
hashtags: "" // omit #, comma seperated "twitter,twitterapi"
}
var intent_url = 'https://twitter.com/intent/tweet?' + $.param(tweet);
$('a#tweet-button').attr('href', intent_url);
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say>The conference will begin when the moderator joins</Say>
<Dial>
<Conference startConferenceOnEnter="false">Room1234</Conference>
</Dial>
</Response>
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Dial action="rollcall.php" method="POST" hangupOnStar="true" timeLimit="1800">
<Conference startConferenceOnEnter="true" endConferenceOnExit="false">Room1234</Conference>
</Dial>
</Response>