Skip to content

Instantly share code, notes, and snippets.

View kuzminT's full-sized avatar

Timofey Kuzmin kuzminT

View GitHub Profile
@kuzminT
kuzminT / postgresql-set-id-seq.sql
Created June 16, 2021 09:57 — forked from henriquemenezes/postgresql-set-id-seq.sql
PostgreSQL set Next ID Sequence Value to MAX(id) from Table
-- Get Max ID from table
SELECT MAX(id) FROM table;
-- Get Next ID from table
SELECT nextval('table_id_seq');
-- Set Next ID Value to MAX ID
SELECT setval('table_id_seq', (SELECT MAX(id) FROM table));
@kuzminT
kuzminT / pymysql_examples.py
Last active May 29, 2019 20:02
Examples for pymysql lib with python 3
""""
:link: https://github.com/PyMySQL/PyMySQL
"""""
import pymysql
import pymysql.cursors
connection = pymysql.connect(host="localhost",
user="root",
password="1234",
@kuzminT
kuzminT / wp_sanitize_file_name.php
Created March 19, 2019 09:26 — forked from edirpedro/wp_sanitize_file_name.php
Translit file names to simple chars, this prevent WordPress to allow accents and special chars at file names that breaks in some server's configuration.
/*
* Translit file names to simple chars,
* this prevent accents and special chars at file names.
***********************************************************************/
function my_sanitize_file_name($filename) {
return remove_accents($filename);
}
add_filter('sanitize_file_name', 'my_sanitize_file_name');
/*
@kuzminT
kuzminT / functions.php
Created February 13, 2019 14:51 — forked from i-like-robots/functions.php
Wordpress custom comment form
<?php
/**
* Comment form hidden fields
*/
function comment_form_hidden_fields()
{
comment_id_fields();
if ( current_user_can( 'unfiltered_html' ) )
{
@kuzminT
kuzminT / autoloader.php
Last active February 8, 2019 20:40
PSR-4 autoloader example
<?php
/**
* An example of a project-specific implementation.
*
* After registering this autoload function with SPL, the following line
* would cause the function to attempt to load the \Foo\Bar\Baz\Qux class
* from /path/to/project/src/Baz/Qux.php:
*
*
* new \Foo\Bar\Baz\Qux;
// getCookie(), setCookie(), deleteCookie()
// возвращает cookie если есть или undefined
function getCookie(name) {
var matches = document.cookie.match(new RegExp(
"(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
))
return matches ? decodeURIComponent(matches[1]) : undefined
@kuzminT
kuzminT / gist:793f516ef268785f8078377bb528b41f
Created February 6, 2019 09:31 — forked from ivandoric/gist:e4e46294c4d35eac0ec8
wordpress: create custom reset password page
<?php //Add all of this tu custom page template ?>
<?php
global $wpdb;
$error = '';
$success = '';
// check if we're in reset form
if( isset( $_POST['action'] ) && 'reset' == $_POST['action'] )
{
@kuzminT
kuzminT / like-it-enqueue.php
Created January 30, 2019 13:01 — forked from shizhua/like-it-enqueue.php
Add a like button without a plugin in WordPress
add_action( 'wp_enqueue_scripts', 'pt_like_it_scripts' );
function pt_like_it_scripts() {
if( is_single() ) {
wp_enqueue_style( 'like-it', trailingslashit( plugin_dir_url( __FILE__ ) ).'css/like-it.css' );
if (!wp_script_is( 'jquery', 'enqueued' )) {
wp_enqueue_script( 'jquery' );// Comment this line if you theme has already loaded jQuery
}
wp_enqueue_script( 'like-it', trailingslashit( plugin_dir_url( __FILE__ ) ).'js/like-it.js', array('jquery'), '1.0', true );
@kuzminT
kuzminT / 20-xdebug.ini
Last active May 1, 2019 13:41
Php tips, docs and usefool links
## Example config for xdebug ini. Use with phpstorm ide.
zend_extension=xdebug.so
xdebug.remote_enable = on
xdebug.remote_connect_back = on
xdebug.remote_host="localhost"
xdebug.remote_port=9010
xdebug.idekey="PHPSTORM"
xdebug.remote_handler=dbgp
xdebug.remote_autostart=1