Skip to content

Instantly share code, notes, and snippets.

View travisfont's full-sized avatar
🍇
// = Earthberries !!

Travis van der F. travisfont

🍇
// = Earthberries !!
View GitHub Profile
@travisfont
travisfont / Skyfire.ORM.php
Created July 6, 2015 17:10
Basic Skyfire ORM Concept
<?php
$data = new DBTable('dsdada');
$data->type = 'color';
$data->name = 'green';
$array = array
(
'id' => 123,
@travisfont
travisfont / file_upload.php
Created July 14, 2015 16:45
PHP File Upload
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
define('UPLOAD_DIRECTORY', 'uploads/'); // directory path for the uploads
define('UPLOAD_HASH', md5(time()));
if (isset($_FILES['file']['name']))
{
@travisfont
travisfont / uploader.html
Created July 14, 2015 16:46
jquery File Upload
<!DOCTYPE html>
<html>
<head>
<title>File Uploader Example</title>
<script src="//code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript">
function submitForm()
{
var fd = new FormData(document.getElementById("fileinfo"));
fd.append("label", "WEBUPLOAD");
@travisfont
travisfont / heredoc_template.php
Created August 11, 2015 15:56
They said it's impossible in PHP, so here you go.. function's and condition statements inside a Heredoc in PHP. it's possible!
<?php
$result = function ($arg1 = false, $arg2 = false)
{
return 'function works';
};
$if = function ($condition, $true, $false) { return $condition ? $true : $false; };
// - ####################################
@travisfont
travisfont / routes.php
Created August 13, 2015 17:15
Basic routing system
<?php
// Define routes
$routes = array
(
'\/' => function() { return '<a href="/hello">Click here for a greeting</a>'; },
'\/hello' => function() { return 'Hello world'; },
'\/count\/(\d+)' => function($count) { return join("<br>", range(1, $count)); },
'404' => function() { return 'Page not found'; }
);
@travisfont
travisfont / wp_get_post_attachments.php
Created August 27, 2015 15:51
Wordpress - How to get a post attachments and post attachment images: get_post_attachments() & get_post_attachment_images()
<?php
function get_post_attachments($post_parent_id, $numberpost = -1, $posts_status = NULL)
{
$args = array
(
'post_type' => 'attachment',
'numberposts' => $numberpost,
'post_status' => $posts_status,
'post_parent' => $post_parent_id
@travisfont
travisfont / method.rules.php
Created September 11, 2015 10:18
Rules function to use in Laravel 5 that handles multiple request method types.
<?php
public function rules()
{
$user = User::find($this->users);
switch($this->method())
{
case 'GET':
case 'DELETE':
@travisfont
travisfont / adding-prefix-all-tables-mysql-database.sql
Created October 22, 2015 14:59
Here's a helpful tip for situations where you need to add a prefix to all of your database tables. Supposing that your database was called "my_database" and the prefix you want to add is "my_prefix", execute the following query.
SELECT Concat('ALTER TABLE ', TABLE_NAME, ' RENAME TO my_prefix_', TABLE_NAME, ';')
FROM information_schema.tables WHERE table_schema = 'my_database'
@travisfont
travisfont / laravel.language.change.php
Last active August 22, 2016 19:49
Laravel's Multilingual Progression (detect and change language whenever)
<?php
namespace App\Http\Middleware;
use Closure;
use Session;
use App;
use Config;
class SetLocale
@travisfont
travisfont / gist:d6cb8c1ac30fe58f033f
Created January 21, 2016 10:42
Converts a string containing an (IPv4) Internet Protocol dotted address into a proper address. SQL: SELECT INET_ATON('83.99.17.115') or PHP: ip2long('83.99.17.115')
var ip2long = function(a,b,c,d){for(c=b=0;d=a.split('.')[b++];)c+=-256&d|b>4?NaN:d*(1<<-8*b);return c};
alert(ip2long('83.99.17.115'));