Skip to content

Instantly share code, notes, and snippets.

View danpette's full-sized avatar

Dan-Petter Jacobsen danpette

View GitHub Profile
@danpette
danpette / gist:b30bc533c942ed5a2ff2
Last active August 29, 2015 14:02
Bootstrap ModalAlert Function
var modals = 0;
function ModalAlert(title, message, confirm, success_function, size, init_ok_disabled) {
modals++;
var is_confirm_modal = (confirm !== undefined && confirm != null && confirm === true) ? true : false;
var size = (size !== undefined && size != null) ? ' ' + size : '';
var ok_disabled = (init_ok_disabled !== undefined && init_ok_disabled != null) ? init_ok_disabled : false;
console.log(ok_disabled);
jQuery('body').append('<div class="overlay"></div>');
jQuery('body').append('<div class="overlay-modal"><div class="modal"><div class="modal-dialog' + size + '"><div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button><h4 class="modal-title">' + title + '</h4></div><div class="modal-body"><p>' + message + '</p></div><div class="modal-footer"><button type="button" class="btn btn-default close-modal-alert" data-dismiss="modal">' + ((is_confirm_modal) ? modal_abort : modal_ok) + '</button>
@danpette
danpette / gist:b342996488ff26a33c26
Created October 3, 2014 15:41
Medoo Error logging
$error = $this->database->error();
if($error[0] != "0000"){
$Log->addError('Class_method('. $Helper::unpack($params).')', [$this->database->error(), $this->database->last_query()]);
}
@danpette
danpette / mysql_to_glacier.php
Created January 6, 2015 06:55
MySQL Dump TO AWS Glacier
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
define('SITE_ROOT', realpath(dirname(__FILE__)));
define('APP_PATH', dirname(__DIR__));
session_cache_limiter(false);
session_start();
$now = time();
$cache_timer = get_option('frontpage_categories_box_cachetime', $now);
if ($cache_timer > $now) {
$content = get_option('frontpage_cateogires_box_content');
if (empty($content)) {
ob_start();
include 'views/frontpage_categories_box.php';
$content = ob_get_clean();
update_option('frontpage_cateogires_box_content', $content);
update_option('frontpage_categories_box_cachetime', (time() + (60 * 60)));
@danpette
danpette / amazone_rds_mysql_connect_with_timeout.php
Created January 29, 2015 21:58
(Amazone RDS) MySQL Connect with forced timeout
error_reporting(E_ALL);
ini_set('display_errors', 1);
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
$time_start = microtime_float();
@danpette
danpette / gist:a4f9cd207f669f99b882
Created February 16, 2015 10:37
Ubuntu 14.04 Setup: nginx + varnish + memcached + php5.6 + mysql5.6 + Mongodb 2.6.7 + phpmyadmin
# Basic
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install htop
sudo apt-get install curl
#MySQL
sudo apt-get install mysql-server-5.6 php5-mysql
sudo mysql_install_db
sudo /usr/bin/mysql_secure_installation
@danpette
danpette / amazone_3s_file_upload_class.php
Created March 3, 2015 08:32
Amazone S3 file upload class
<?php
namespace Somewhere\Model;
class Upload {
public function __construct() {}
public function addFile($post_name, $directory = '/usr/share/nginx/files/') {
global $s3, $Log; //S3 library and Monolog
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;
using System.Web;
namespace Admin.Helpers
{
public class IQueryablePropertyHelper
@danpette
danpette / ubuntu_1404_lemp_node.txt
Last active August 29, 2015 14:18
Ubuntu LEMP Node V1
#Require: Ubuntu 14.04
#nginx
sudo apt-get update
sudo apt-get install nginx
sudo service nginx start
#Timezone
sudo dpkg-reconfigure tzdata
@danpette
danpette / deploy.sh
Created July 16, 2015 08:47
deploy sudo
#create build folder
mkdir deploy
#download latest version
git clone blablabla deploy
#composer
php composer self-update
php composer update
#deploy new version
mv deploy /
#Clean