Skip to content

Instantly share code, notes, and snippets.

View ivankristianto's full-sized avatar

Ivan Kristianto ivankristianto

View GitHub Profile
@ivankristianto
ivankristianto / install_docker.Docker
Created June 19, 2016 08:58
Install Redis on php5 docker
RUN curl -L -o /tmp/redis.tar.gz https://github.com/phpredis/phpredis/archive/2.2.7.tar.gz \
&& tar xfz /tmp/redis.tar.gz \
&& rm -r /tmp/redis.tar.gz \
&& mv phpredis-2.2.7 /usr/src/php/ext/redis \
&& docker-php-ext-install redis
@ivankristianto
ivankristianto / install_memcache_docker.txt
Created June 15, 2016 03:16
Install PHP Memcache in docker php
PHP 5.6:
RUN apt-get update \
&& apt-get install -y libmemcached11 libmemcachedutil2 build-essential libmemcached-dev libz-dev \
&& pecl install memcached \
&& echo extension=memcached.so >> /usr/local/etc/php/conf.d/memcached.ini \
&& apt-get remove -y build-essential libmemcached-dev libz-dev \
&& apt-get autoremove -y \
&& apt-get clean \
&& rm -rf /tmp/pear
# Remove all stopped containers.
docker rm $(docker ps -a -q)
#Remove all untagged images
docker rmi $(docker images | grep "^<none>" | awk "{print $3}")
@ivankristianto
ivankristianto / remove_unused_docker_containers.sh
Created May 1, 2016 13:18
Remove unused docker containers
sudo docker ps -a | grep Exit | cut -d ' ' -f 1 | xargs sudo docker rm
@ivankristianto
ivankristianto / ip_is_private.php
Created March 25, 2016 10:11
Check if my ip is private
<?php
function ip_is_private ($ip) {
$pri_addrs = array (
'10.0.0.0|10.255.255.255', // single class A network
'172.16.0.0|172.31.255.255', // 16 contiguous class B network
'192.168.0.0|192.168.255.255', // 256 contiguous class C network
'169.254.0.0|169.254.255.255', // Link-local address also refered to as Automatic Private IP Addressing
'127.0.0.0|127.255.255.255' // localhost
);
@ivankristianto
ivankristianto / array_to_csv_download.php
Last active November 22, 2019 12:09
Export Import CSV
<?php
function array_to_csv_download($array, $filename = "export.csv", $delimiter=";") {
// open raw memory as file so no temp files needed, you might run out of memory though
$f = fopen('php://memory', 'w');
// loop over the input array
foreach ($array as $line) {
// generate csv lines from the inner arrays
fputcsv($f, $line, $delimiter);
}
// reset the file pointer to the start of the file
@ivankristianto
ivankristianto / imap_helper.php
Last active October 11, 2015 14:52
PHP IMAP Helper function
<?php
function fetch_imap( $host, $username, $password, $port ){
$hostname = '{'.$host.':'.$port.'/imap/ssl/novalidate-cert}INBOX';
/* try to connect */
$inbox = imap_open( $hostname, $username, $password )
or die("Can't connect to '$hostname': " . var_dump(imap_errors()) );
// or die('Cannot connect to Gmail: ' . imap_last_error());
/* grab emails */
$emails = imap_search( $inbox, 'UNSEEN' );
@ivankristianto
ivankristianto / server_to_server.php
Created October 1, 2015 05:05
Download file server to server
<?php
set_time_limit(0);
file_put_contents( 'progress.txt', '' );
$targetFile = fopen( 'filename.zip', 'w' );
$ch = curl_init( 'URL to File' );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt( $ch, CURLOPT_NOPROGRESS, false );
@ivankristianto
ivankristianto / sam-ajax.php
Created April 4, 2015 14:44
sam-ajax security fixed
<?php
/**
* Author: minimus
* Date: 24.10.13
* Time: 12:14
*/
define('DOING_AJAX', true);
if (!isset( $_POST['action'])) die('-1');
@ivankristianto
ivankristianto / scrollable_fixed_sidebar
Last active August 29, 2015 14:17
Scrollable and Fixed Sidebar
jQuery(document).ready(function($){
var $body, $window, $sidebar, adminbarOffset, headerHeight, top = false,
bottom = false, windowWidth, windowHeight, lastWindowPos = 0,
topOffset = 0, bodyHeight, sidebarHeight, sidebarWidth, resizeTimer;
// Sidebar scrolling.
function resize() {
windowWidth = $window.width();
windowHeight = $window.height();
bodyHeight = $body.height();