Skip to content

Instantly share code, notes, and snippets.

@legierski
legierski / phpconsole_helper.php
Last active August 29, 2015 13:58
Phpconsole helper file for Codeigniter (https://phpconsole.com)
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
include(APPPATH.'third_party/phpconsole.php');
class phpconsole_helper {}
@legierski
legierski / gathercontent_api_v0_4.php
Last active May 10, 2022 01:56
GatherContent API example (v0.4)
<?php
class Example_API {
private $api_url;
private $api_key;
private $password;
/**
* Class Constructor
@legierski
legierski / convert_from_new_config_structure.php
Created January 29, 2014 16:35
Convert new data format to the old one ( GatherContent API, >=v0.3) https://help.gathercontent.com/developer-api/
<?
function foreach_safe($arr) {
if(is_array($arr)) {
if(count($arr) > 0) {
return true;
}
}
return false;
@legierski
legierski / CodeIgniter-snippet.php
Last active January 5, 2017 05:23
CodeIgniter 2.1.3 (and older) overwriting time limit to 300s. Comment it out / delete entirely to let your server control time limit
<?
/*
* ------------------------------------------------------
* Set a liberal script execution time limit
* ------------------------------------------------------
*/
if (function_exists("set_time_limit") == TRUE AND @ini_get("safe_mode") == 0)
{
@set_time_limit(300);
@legierski
legierski / gist:5174309
Created March 16, 2013 00:35
.production / .development switch for your PHP codebase
if(file_exists('.production')) {
define('ENVIRONMENT', 'production');
}
else if(file_exists('.development')) {
define('ENVIRONMENT', 'development');
}
else {
exit('Missing .production/.development file.');
}
@legierski
legierski / calculate-indentation.php
Created November 17, 2012 15:09
Calculate how much indentation there is in your PHP project
<?
$spaces = calculate_spaces('folder-name');
echo 'Spaces and tabs used for indentation account for '.$spaces['percent'].'% of selected folder\'s files ('.$spaces['spaces'].' spaces, '.$spaces['total'].' total characters).';
function calculate_spaces($path) {
$spaces_counter = 0;
@legierski
legierski / MY_download_helper.php
Created October 9, 2012 19:38
Fixing download helper in CodeIgniter 2.1.3
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
if ( ! function_exists('force_download2'))
{
function force_download2($filename = '', $data = '')
{
if (FALSE === strpos($filename, '.'))
{
$filename .= '.noextension';
}
@legierski
legierski / am-i-logged-in.php
Created May 22, 2012 21:41
php for am-i-logged-in
public function am_i_logged_in() {
if(!IS_AJAX) {
echo 'Hi there!<br><br>In case you were wondering - the address that you\'ve just visited is used by us to check if you\'re still logged into GatherContent, and if, by any chance, your browser logs you out - we will display information within the app to prevent data loss!';
exit;
}
$json = array();
if(!$u = Current_User::user()) {
@legierski
legierski / am-i-logged-in.js
Created May 22, 2012 21:38
js for am-i-logged-in
$(document).ready(function() {
am_i_logged_in_interval = setInterval("am_i_logged_in()", 60000);
});
function am_i_logged_in() {
address = window.location.protocol+'//'+window.location.hostname+'/am-i-logged-in';
$.ajax({
type: "POST",
@legierski
legierski / redbean_example_2.php
Created April 17, 2012 23:30
RedBean example 2
$user = R::dispense(‘user’);
$user->email = ‘peter@legierski.net’; // that’s all it takes
$user->login = ‘legierski’;
$user->password = ‘H4XX0RP4SSW0RD’;
R::store($user);