Skip to content

Instantly share code, notes, and snippets.

View kosinix's full-sized avatar

Kosinix kosinix

  • Philippines
View GitHub Profile
@kosinix
kosinix / tpl.php
Created January 30, 2014 11:42
Learn what template you are in WordPress
<?php
function template_hierarchy_detector(){
$out = array();
if ( is_404() ) {
$out[] = 'Error 404 Page';
}
if( is_search() ){
$out[] = 'Search Result Page';
}
if( is_archive() ){
<?php
function get_pages_tree($parent_id=0){
$args = array(
'parent'=>$parent_id
);
$pages = get_pages( $args );
if($pages){
@kosinix
kosinix / get_pages_flattened_tree.php
Created February 3, 2014 11:12
Wordpress flat list
<?php
function get_pages_flattened_tree(&$flattened_list, $parent_id=0, $level=0){
$args = array(
'parent'=>$parent_id
);
$pages = get_pages( $args );
if($pages){
@kosinix
kosinix / gist:7d8f19352782ff598e1f
Created August 20, 2014 00:04
Disable Post Revision and Delay Autosave in WP
wp-config.php:
define('AUTOSAVE_INTERVAL', 300 ); // seconds
define('WP_POST_REVISIONS', false );
SQL:
DELETE FROM wp_posts WHERE post_type = "revision";
@kosinix
kosinix / gist:993b09fbb3389e44391b
Created September 4, 2014 05:49
C# - Delete a folder in a zip using dotnetzip. Docs: http://dotnetzip.herobo.com/DNZHelp/Index.html
using (ZipFile zip = ZipFile.Read(@"D:\path\to\ZipFile.zip"))
{
zip.RemoveSelectedEntries("foldername/*"); // Remove folder and all its contents
zip.Save();
}
@kosinix
kosinix / generateRandomString.php
Last active August 29, 2015 14:06
Generate Password 12 characters long with some characters removed (l,1,0,o) for readability
<?php
function generateRandomString($length = 12) {
$characters = '23456789abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ !@#$%^&*()_-';
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, strlen($characters) - 1)];
}
return $randomString;
}
@kosinix
kosinix / get_properties.php
Created September 17, 2014 01:37
Get all class properties at once and put it in an array
<?php
class Foo {
protected $var1;
protected $var2;
/* Get Properties
*
* Get all class properties at once and put it in an array
*
* @return array $class_vars
@kosinix
kosinix / gist:5ec1732db6068ec08854
Created October 30, 2014 11:12
Force shutdown windows in 60 seconds
shutdown -s -f -t 60
@kosinix
kosinix / gist:f9c451eb6f9ccf34fc35
Last active August 29, 2015 14:09
Construct URL using symfony httpfoundation request
$request->getScheme().'://'.$request->getHttpHost().$request->getBasePath().$request->getPathInfo();
@kosinix
kosinix / mklink
Created January 26, 2015 01:00
Symbolic links in windows 7