Skip to content

Instantly share code, notes, and snippets.

Avatar

Roger Stringer freekrai

View GitHub Profile
@freekrai
freekrai / slugify.php
Created Mar 16, 2014
convert text to slugs
View slugify.php
<?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 Jun 19, 2014
call get_thumb_url
View loop.php
<?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 Jul 23, 2014
Grab latest images via instagram
View functions.php
<?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 Aug 29, 2015
Add rewrite capabilites to PHP 5.4's built-in web server
View routing.php
<?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';
}
View 1-Install-PHP54-MySQL5-PostgreSQL.md

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

View is_base64.php
<?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;
View gist:ca5f573e3801c4985215
<?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';
View gist:04f263824fd0449ac959
<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);
View conferencemod.xml
<?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>
View rollcall.php
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library
// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXX";
$token = "YYYYY";
$client = new Services_Twilio($sid, $token);
$response = new Services_Twilio_Twiml();