Skip to content

Instantly share code, notes, and snippets.

View kythin's full-sized avatar

Chris Samios kythin

View GitHub Profile
@kythin
kythin / deploy.sh
Created May 27, 2014 01:00
Website Deploy Script (Bash + lftp)
#!/bin/bash
##########
# Deploy Script
# for deploying to servers that don't have git or ssh access
# RUN THIS FROM A VAGRANT SSH IF YOU AREN'T ON LINUX ALREADY.
##########
# prevents the certificate verification error.
sudo echo "set ssl:verify-certificate no" > ~/.lftp/rc
@kythin
kythin / cap.sh
Created May 26, 2014 06:54
RTMP to JPG Timelapse Capture Bash Script
#!/bin/bash
##
# RTMP to JPEG timelapse script
# github.com/kythin
#
# Simple script to take an RTMP streaming url and save a jpeg every 10 seconds.
#
# Requires 'ffmpeg' and 'rtmpdump'
# apt-get install ffmpeg rtmpdump
@kythin
kythin / share.js
Created April 15, 2014 23:29
JS Social share functions
function fbShare(url, title, descr, image, winWidth, winHeight) {
var winTop = (screen.height / 2) - (winHeight / 2);
var winLeft = (screen.width / 2) - (winWidth / 2);
title = encodeURIComponent(title);
url = encodeURIComponent(url);
descr = encodeURIComponent(descr);
image = encodeURIComponent(image);
window.open('http://www.facebook.com/sharer.php?s=100&p[title]=' + title + '&p[summary]=' + descr + '&p[url]=' + url + '&p[images][0]=' + image, 'sharer', 'top=' + winTop + ',left=' + winLeft + ',toolbar=0,status=0,width=' + winWidth + ',height=' + winHeight);
@kythin
kythin / max_upload.php
Created April 1, 2014 04:42
PHP Upload Size
<?php
function getMaxUploadMB() {
$max_upload = (int)(ini_get('upload_max_filesize'));
$max_post = (int)(ini_get('post_max_size'));
$memory_limit = (int)(ini_get('memory_limit'));
$upload_mb = min($max_upload, $max_post, $memory_limit);
return $upload_mb;
}
@kythin
kythin / http.php
Created March 31, 2014 04:38
HTTP/HTTPS (PHP)
<?php
/**
* http
* Echo's or returns the http starter section of the url.
* Use this to prevent SSL errors where some stuff is http and some is https.
* @param bool $return
* @return string
*/
function http($return = false) {
$http = "http://";
@kythin
kythin / isMobileDevice.php
Created March 26, 2014 01:15
Check if Mobile Device PHP Function
function isMobileDevice() {
$user_agent = strtolower ( $_SERVER['HTTP_USER_AGENT'] );
if ( preg_match ( "/phone|iphone|itouch|ipod|symbian|android|htc_|htc-|palmos|blackberry|opera mini|iemobile|windows ce|nokia|fennec|hiptop|kindle|mot |mot-|webos\/|samsung|sonyericsson|^sie-|nintendo/", $user_agent ) ) {
// these are the most common
return true;
} else if ( preg_match ( "/mobile|pda;|avantgo|eudoraweb|minimo|netfront|brew|teleca|lg;|lge |wap;| wap /", $user_agent ) ) {
// these are less common, and might not be worth checking
return true;
}
}
@kythin
kythin / Blitline.php
Created March 7, 2014 04:59
Blitline SDK for PHP, super basic and enough for you to start running things from their examples http://www.blitline.com/docs/examples
<?php
/**
* Class Bitline
*
* by github.com/kythin
*
* http://www.blitline.com/docs/examples
*
* Very basic starter SDK for PHP for this awesome service! From this code you should be able to do pretty much anything.
@kythin
kythin / getLikesCountForURL.php
Created January 10, 2014 05:27
Get the number of facebook liked for a URL (which would include links to images, etc)
function getLikesCountForURL($url) {
$fullurl = 'https://api.facebook.com/method/fql.query?query=SELECT%20like_count%20FROM%20link_stat%20WHERE%20url=%22'.$url.'%22&format=json';
$response = json_decode(file_get_contents($fullurl),true);
return $response[0]['like_count'];
}
@kythin
kythin / toggl_v8_sdk.php
Last active December 23, 2015 01:39
Basic beginnings of a Toggl.com API version 8 PHP SDK. Currently only supports returning the logged in user, and submitting a new session to an existing workspace/project/task id. Other functions should be pretty easy to implement by copying the 'me' function for GET's, or the 'timeEntrySave' for POST's.
<?php
/**
* Toggl v8 PHP SDK
* @author github.com/kythin ([email protected])
* @version 1.0
*
* Do-whatever-you-want-except-sell-it license, feel free to fork and improve! I think that means GPLv3 right?
*
* I've gone through some of the examples in https://github.com/toggl/toggl_api_docs/tree/master/chapters (new v8 api docs)
* and implemented a handful of the ones I was using in old scripts, so check them out and if you add more support please
@kythin
kythin / force_ssl.php
Created July 23, 2013 23:22
Force a page to use HTTPS using this function.
function forceSSL() {
if($_SERVER["HTTPS"] != "on") {
header("HTTP/1.1 301 Moved Permanently");
header("Location: https://" . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]);
exit();
}
}