Skip to content

Instantly share code, notes, and snippets.

Avatar
🐕

Tomek Kobyliński cobyl

🐕
View GitHub Profile
View sample.sql
CREATE TABLE `customer` (
`id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
`npid` char(8) CHARACTER SET ascii NOT NULL,
`email` char(254) CHARACTER SET ascii DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `npid` (`npid`),
) ENGINE=InnoDB AUTO_INCREMENT=32 DEFAULT CHARSET=utf8;
DELIMITER ;;
CREATE trigger before_insert_customer BEFORE INSERT ON customer FOR EACH ROW
View spanSplit
<?php
function spanSplit($string) {
function mb_str_split( $string, $string_length = 1, $charset = 'utf-8' ) {
if ( mb_strlen( $string, $charset ) > $string_length || !$string_length ) {
do {
$c = mb_strlen( $string, $charset );
$parts[] = mb_substr( $string, 0, $string_length, $charset );
$string = mb_substr( $string, $string_length, $c - $string_length, $charset );
} while ( !empty( $string ) );
} else {
View designer.html
<link rel="import" href="../core-icon-button/core-icon-button.html">
<link rel="import" href="../core-toolbar/core-toolbar.html">
<link rel="import" href="../core-scroll-header-panel/core-scroll-header-panel.html">
<polymer-element name="my-element">
<template>
<style>
#core_scroll_header_panel {
width: 380px;
View slug.php
<?php
function generateSlug($string, $separator = '-') {
// nowa magia PHP 5.4 & intl
$transliterator = \Transliterator::create("Any-Latin; Latin-ASCII; NFD; [:Nonspacing Mark:] Remove; NFC; [:Punctuation:] Remove; Lower();");
$string = $transliterator->transliterate($string);
//TODO przeklejone z starej funkcji - zapewne to powyżej większość z tego umie; część nadmiarowa
return strtolower(trim(preg_replace('~[^0-9a-z]+~i', '-', html_entity_decode(preg_replace('~&([a-z]{1,2})(?:acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml);~i', '$1', htmlentities($string, ENT_QUOTES, 'UTF-8')), ENT_QUOTES, 'UTF-8')), '-'));
}
@cobyl
cobyl / UserTable.php
Created Jul 16, 2013
i jeszcze dodatkowe przykłady
View UserTable.php
<?php
$this->tablegateway->select(function (\Zend\Db\Sql\Select $select) use ($params){
// kolumna created = updated
$select->where->equalTo('id','created');
// i pole like zawiera cos tam szukanego
$select->where->AND->like('name',"%".$params['search']."%");
// i pole email jest test@test.pl albo z domeny @test.com
$select->where->AND->NEST->equalTo('email','test@test.pl')->OR->like('email','%@test.com');
// a do tego jeszcze parametr email malymi literkami równa ... itd
$select->where->addPredicate(new \Zend\Db\Sql\Predicate\Expression("LOWER(email) = ?",$params['email']));
@cobyl
cobyl / UserTable.php
Last active Dec 19, 2015
Przykład użycia sensownej składni selectów
View UserTable.php
<?php
$this->tablegateway->select(function (\Zend\Db\Sql\Select $select) use ($params){
// kolumna created = updated
$select->where->equalTo('created','updated');
});
@cobyl
cobyl / Module.php
Last active Dec 19, 2015
Dodanie do nawigacji zalolguj/wyloguj zależnie od tego czy jest się zalogowanym.
View Module.php
<?php
public function onBootstrap(MvcEvent $e) {
if ($e->getApplication()->getServiceManager()->get('AuthStorage')->hasIdentity())
$pages = new \Zend\Navigation\Page\Mvc(array(
'pages'=>
array(
'auth-user-logout' => array(
'label' => 'Wylogowanie',
'route' => 'auth-user-login',
)
You can’t perform that action at this time.