Skip to content

Instantly share code, notes, and snippets.

@stajnert
stajnert / Remove \n and \r mysql
Created August 17, 2012 11:19
Remove \n and \r from column
UPDATE table SET column = REPLACE(REPLACE(column, '\r', ''), '\n', '');
@stajnert
stajnert / duplicates.sql
Created August 21, 2012 07:08
Get duplicates from mysql
Single records:
SELECT column, COUNT(*) AS c
FROM table
GROUP BY column
HAVING COUNT(c) > 1
All records:
SELECT *
@stajnert
stajnert / sfWidgetFormChoiceFormatter.php
Created August 23, 2012 11:00
sfWidgetFormChoice formatter - every <li> put in new line
/**
* Metoda konfiguruje formularz
*/
public function configure()
{
$this->widgetSchema['cities'] = new sfWidgetFormChoice(array(
'expanded' => true,
'multiple' => true,
'choices' => Doctrine_Core::getTable('hall')->getListNameForOpenHall(),
'renderer_options' => array('formatter' => array($this, 'formatter'))
@stajnert
stajnert / File extension.php
Created August 28, 2012 10:14
Get file extension
function getFileExtension($file_name)
{
return substr(strrchr($file_name, '.'), 1);
}
@stajnert
stajnert / even_odd.php
Created August 29, 2012 06:31
Even odd tr
<?php foreach ($jobs as $i => $job): ?>
<tr class="<?php echo fmod($i, 2) ? 'even' : 'odd' ?>">
<?php endforeach; ?>
@stajnert
stajnert / slugify.php
Last active October 11, 2015 07:38
Function creates url properly slug from $text
<?php
/**
* Function creates url properly slug from $text
*
* @param string $text
*/
public function slugify($text)
{
// replace non letter or digits by -
$text = preg_replace('#[^\\pL\d]+#u', '-', $text);
@stajnert
stajnert / FlxZipArchive.class.php
Created December 18, 2012 13:13
Extended ZipArchive - simply way to create zip with subdirectories
<?php
class FlxZipArchive extends ZipArchive
{
/**
* Add a Dir with Files and Subdirs to the archive
*
* @param string $location Real Location
* @param string $name Name in Archive
@stajnert
stajnert / browser.html
Last active August 2, 2018 03:54
Javascript to find browser version, os version and os bit version
<html>
<body>
<script type="text/javascript">
var BrowserDetect = {
init: function () {
this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
this.version = this.searchVersion(navigator.userAgent)
|| this.searchVersion(navigator.appVersion)
|| "an unknown version";
this.OS = this.searchString(this.dataOS) || "an unknown OS";
@stajnert
stajnert / integer.js
Last active December 13, 2015 23:48
Fetch integer from attr
var int = $(this).attr('id').match(/\d+/);
@stajnert
stajnert / strongPassword.php
Last active December 14, 2015 23:49
Function generates strong password with parameters
<?php
/**
* Function generates password depend on configuration sets
*
* @param int $length
* @param boolean $add_dashes
* @param string $available_sets
* @return string
*/
public static function generateStrongPassword($length = 10, $add_dashes = false, $available_sets = 'luds')