Skip to content

Instantly share code, notes, and snippets.

View gcphost's full-sized avatar

William gcphost

View GitHub Profile
@gcphost
gcphost / gist:448a9fe398604b0f7b81
Created June 28, 2015 03:20
jQuery JSON Form Post
# As-seen-at https://asked.io/jquery-json-post-form-data
$.fn.postJson = function(success) {
return this.each(function() {
$(this).on('submit', function(){
$.post( $(this).data('action'), $(this).serialize(), success, "json");
return false;
});
});
};
@gcphost
gcphost / gist:2a942b57fa1d728fc04a
Created June 29, 2015 03:10
Sinatra MVC Style Module
module Sinatra::Hi
module Helpers
def conf
@page_title = 'Hi :D'
end
end
def self.registered(app)
app.helpers Helpers
@gcphost
gcphost / gist:fe9f02696dfc06c44faa
Last active August 29, 2015 14:24
PHP SSH2 Wrapper
<?php
class SSH{
var $host='';
var $port='';
var $user='';
var $pass='';
var $connection='';
var $sudo='';
var $authed=false;
@gcphost
gcphost / gist:8720d4e183154015e4bb
Created July 9, 2015 18:50
Simple PHP Website Status Check and Report
<?php
$failed=true;
if($site=file_get_contents('http://google.com')){
if(preg_match('/google/', $site)) $failed=false;
# Maybe your sites online but has an error..
# if(preg_match('/Something went wrong/', $site)) $failed=true;
}
if($failed) mail('you @ tld.com', 'Site OFFLINE', 'WTF dude!');
@gcphost
gcphost / gist:92aa9af61d919d348934
Created July 10, 2015 21:29
PHP Simple Stats, CPU, Memory, Disc and Load Usage
<?php
$load=sys_getloadavg();
$results=array(
'memory' => round(exec("printf \$(free -m| grep Mem | awk '{ print \$3/\$2*100 }')"),2),
'disc' => (100-round(disk_free_space(getcwd())/disk_total_space (getcwd()) * 100,2)),
'cpu' => round(exec("grep 'cpu ' /proc/stat | awk '{cpu_usage=($2+$4)*100/($2+$4+$5)} END {print cpu_usage}'"),2),
'load' => $load[0]
);
die(json_encode($results));
@gcphost
gcphost / gist:f5fb4087de067e8df23e
Created July 11, 2015 15:29
PHP Simple Stats v2
<?php
class SimpleStats {
private $url = 'http://localhost/';
private $lock = '.stats.lock';
private $network = 'lo';
private $response = '/Unable to locate domain/';
private $procs = array(
'/usr/sbin/mysqld',
'/usr/sbin/lighttpd',
@gcphost
gcphost / gist:3f3c46f15e4e86c58bff
Created July 12, 2015 05:50
CPP Curl Retrieve Website
#include <curl/curl.h>
using namespace std;
string contents="";
string check_url(string url){
string results="";
curl_global_init(CURL_GLOBAL_SSL );
CURL* curl = curl_easy_init();
if(curl) {
curl_easy_setopt (curl,CURLOPT_SSL_VERIFYHOST, 0L);
<link rel="stylesheet" property="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/css/select2.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/js/select2.min.js"></script>
<script>
$("#category").select2({
tags: true, placeholder :'Categories', width: '100%'
});
$("#tags").select2({
tags: true, placeholder :'Tags', width: '100%'
});
$('.layout-picker').on('click', function(){
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Response;
class Minify
{
public function handle($request, Closure $next)
@gcphost
gcphost / default.conf
Created January 25, 2016 04:00
Nginx default.conf for gzip and cache
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/html/public;
index index.php index.html index.htm;
server_name localhost;
charset utf-8;