Skip to content

Instantly share code, notes, and snippets.

View velosipedist's full-sized avatar

Nick Konev velosipedist

View GitHub Profile
@velosipedist
velosipedist / wordpress-photo-digest
Last active December 19, 2015 09:59
Quick way to list images from Wordpress posts without using "attachment" ("media") posts. Just parse some fresh posts to list found <img/> tags.
<?php
// fetch fresh published posts
$imgPosts = get_posts(array(
'posts_per_page' => 10, // max count
'orderby' => 'post_modified',
'order' => 'DESC',
'post_type' => 'post',
'post_status' => 'publish'
));
@velosipedist
velosipedist / rewrite.apacheconf
Last active December 25, 2015 10:59
Change web root using .htaccess. Can be used in Laravel bootstrapped app, or in any project under localhost with spec
# for example, we are in /www/htdocs/myproject
# but webroot situated in /www/htdocs/myproject/public_html
# let's create /www/htdocs/myproject/.htaccess
RewriteEngine on
RewriteCond %{REQUEST_URI} !public_html/
RewriteRule (.*) public_html/$1 [L]
@velosipedist
velosipedist / postgresql-list-foreign-keys.sql
Created October 31, 2013 13:52
List all foreign keys in PostgreSQL database, analog of MySQL SHOW CREATE TABLE mytable;
--- Source: http://solaimurugan.blogspot.ru/2010/10/list-out-all-forien-key-constraints.html
SELECT
tc.constraint_name,
tc.constraint_type,
tc.table_name,
kcu.column_name,
tc.is_deferrable,
tc.initially_deferred,
rc.match_option AS match_type,
@velosipedist
velosipedist / ordered-lists.less
Last active December 27, 2015 20:29
HTML Ordered lists custom marker using CSS and `:before` pseudo-class
ol {
counter-reset: custom-counter-name; // any name, use afterwards for incrementing counter
// counter-reset: custom-counter-name 1; // can be started from custom index
li{
list-style:none;
counter-increment: custom-counter-name;
}
li:before {
content: "[" counter(custom-counter-name) "]";
@velosipedist
velosipedist / todo.php
Last active December 28, 2015 10:49
Web script that exctracts 'todo' comments or all of comments from given dir. Use only on local machine! Unsafe!
<?php
//todo use composer global vendor path
require('c:\Users\user\AppData\Roaming\Composer\vendor\autoload.php');
use Underscore\Types\Arrays;
use Underscore\Types\String;
use CallbackFilterIterator as CI;
use RecursiveDirectoryIterator as DI;
use RecursiveiteratorIterator as RI;
use RecursiveRegexIterator as REI;
@velosipedist
velosipedist / emoji-img.html
Last active December 30, 2015 11:58
github emoji evrywhere
<img width=24 src=//github.global.ssl.fastly.net/images/icons/emoji/confused.png />
@velosipedist
velosipedist / var_debug.php
Last active December 31, 2015 22:29
Php var_dump() analog for console output, from this post: http://www.leaseweblabs.com/2013/10/smart-alternative-phps-var_dump-function/
<?php
function var_debug($variable,$strlen=100,$width=25,$depth=10,$i=0,&$objects = array())
{
$search = array("\0", "\a", "\b", "\f", "\n", "\r", "\t", "\v");
$replace = array('\0', '\a', '\b', '\f', '\n', '\r', '\t', '\v');
$string = '';
switch(gettype($variable)) {
case 'boolean': $string.= $variable?'true':'false'; break;
# PLUGIN MEDIATOR FOR DOC-BASED KEYS
class docStreamWrapper
# ... garbage
def getContents(filename)
return translator.translateFile(filename.withoutProtocol 'doc://')
end
end
# PLUGIN MEDIATOR FOR SIGNATURE BASED KEYS
class classVisitor
@velosipedist
velosipedist / FileStreamWrapper.php
Created December 26, 2013 08:12
Stream wrapper around existing file
<?php
namespace velosipedist\sami\translator;
/**
* Implements necessary methods for use with stream_wrapper_register($this->protocol, FileStreamWrapper)
* There is only needed method to implement — process()
*/
abstract class FileStreamWrapper
{
/**
@velosipedist
velosipedist / chmod.php
Last active January 2, 2016 17:59
Chmod over all dirs & files separately, when no ssh around
<?php
`cd "../.."; chmod 777 $(find ./* -type d); chmod 666 $(find ./* -type f)`;