Skip to content

Instantly share code, notes, and snippets.

View ivankristianto's full-sized avatar

Ivan Kristianto ivankristianto

View GitHub Profile
<?php
/*
Plugin Name: Disable plugins when doing local dev
Description: If the WP_LOCAL_DEV constant is true, disables plugins that you specify
Version: 0.1
License: GPL version 2 or any later version
Author: Mark Jaquith
Author URI: http://coveredwebservices.com/
*/
@ivankristianto
ivankristianto / check_php_codesniffer
Last active August 29, 2015 14:16
Check code PHP code with Codesniffer and use WordPress standard
ivan@ivan:~/missions/wptest/src/wp-content/themes/calibrefx$ sudo phpcs --standard=WordPress $(find . -name '*.php')
ivan@ivan:~/missions/wptest/src/wp-content/themes/calibrefx$ phpcbf --standard=WordPress comments.php
Setup PHP code sniffer with WordPress standard
http://subharanjan.com/setup-php-codesniffer-along-wordpress-coding-standards-windows-xampp/
ivan@ivan:/usr/share/php/PHP/CodeSniffer/Standards/WordPress$
@ivankristianto
ivankristianto / xclip_to_clipboard
Created March 15, 2015 02:57
Copy to id_rsa.pub to clipboard
xclip -sel clip < ~/.ssh/id_rsa.pub
@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();
@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 / 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 / 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 / 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 / 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 / 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