Skip to content

Instantly share code, notes, and snippets.

View tlongren's full-sized avatar
👋
hiiii

Tyler Longren tlongren

👋
hiiii
View GitHub Profile
@tlongren
tlongren / functions.php
Last active October 11, 2018 15:11
Auto Get Schema Type By Post Type
<?php
function html_tag_schema() {
$schema = 'http://schema.org/';
// Is single post
if(is_single()) {
$type = "Article";
}
// Is author page
@tlongren
tlongren / help.md
Created February 16, 2014 19:30
AltoRouter Named Parameter Limits

You can use the following limits on your named parameters. AltoRouter will create the correct regexes for you.

*                    // Match all request URIs
[i]                  // Match an integer
[i:id]               // Match an integer as 'id'
[a:action]           // Match alphanumeric characters as 'action'
[h:key]              // Match hexadecimal characters as 'key'
[:action]            // Match anything up to the next / or end of the URI as 'action'
[create|edit:action] // Match either 'create' or 'edit' as 'action'
@tlongren
tlongren / charge.php
Created February 16, 2014 19:27
AltoRouter charge.php
<?php
$customer = new Customer();
$customer_id = $match['params']['customer_id'];
if ($customer->valid_customer($customer_id) && $customer->needs_paid($customer_id)) {
$customer->pay($customer_id);
}
?>
@tlongren
tlongren / index.php
Last active August 29, 2015 13:56
AltoRouter index.php
<?php
header("Content-Type: text/html");
include dirname(__FILE__) . '/includes/AltoRouter.php';
$router = new AltoRouter();
$router->setBasePath('');
/* Setup the URL routing. This is production ready. */
// Main routes that non-customers see
$router->map('GET','/', 'home.php', 'home');
@tlongren
tlongren / .htaccess
Last active October 15, 2015 03:14
AltoRouter htaccess
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /index.php [L]
<?php
define('PAPERTRAIL_PORT','123456');
function send_remote_syslog($message, $component = "web", $program = "next_big_thing") {
$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
foreach(explode("\n", $message) as $line) {
$syslog_message = "<22>" . date('M d H:i:s ') . $program . ' ' . $component . ': ' . $line;
socket_sendto($sock, $syslog_message, strlen($syslog_message), 0, 'logs.papertrailapp.com', PAPERTRAIL_PORT);
}
socket_close($sock);
}
@tlongren
tlongren / index.php
Created December 12, 2013 19:47
Simple personal API with static array and PHP
<?php
header('Content-Type: application/json');
$dob = "8/17/1983";
$json = '{
"person": {
"age": {
"years": 23,
"months": 8,
"weeks": 2,
"days": 5,
@tlongren
tlongren / index.php
Created October 25, 2013 01:53
AltoRouter index.php
<?php
header("Content-Type: text/html");
require 'AltoRouter.php';
$router = new AltoRouter();
$router->setBasePath('');
/* Setup the URL routing. This is production ready. */
$router->map('GET','/', 'home.php', 'home');
$router->map('GET','/home/', 'home.php', 'home-specific');
$router->map('GET','/home', 'home.php', 'home-specific-noslash');
@tlongren
tlongren / .htaccess
Created October 21, 2013 05:22
Wicd.net .htaccess Redirection
RewriteEngine on
RewriteCond %{REQUEST_URI} !https://launchpad.net/wicd$
RewriteRule $ https://launchpad.net/wicd [R=301,L]
@tlongren
tlongren / addService.php
Last active November 25, 2021 04:07
Stripe Setup as of July 12
<?php
require_once("/srv/www/vpsstat.us/public_html/includes/stripe-php/lib/Stripe.php");
Stripe::setApiKey("sk_test_xxxxxxxxxxxxxxxxxxxxxxxx");
$token = ($_GET['stripeToken']) ?$_GET['stripeToken'] : $_POST['stripeToken'];
$customerDetails = get_customer_details($customer_id);
if (empty($customerDetails['stripe_id'])) {
$customer = Stripe_Customer::create(array(
"card" => $token,
"plan" => "standard",
"email" => $customerDetails['email']