Skip to content

Instantly share code, notes, and snippets.

@stajnert
stajnert / updateForm.php
Created July 12, 2013 09:28
Change values before bind
<?php
$values = $request->getParameter($form->getName());
$values['yourdate'] = NEW MODIFIED DATE VALUE;
$form->bind($values, $request->getFiles($form->getName()));
$o = $form->getObject();
$o->save();
?>
@stajnert
stajnert / json_plus
Created May 20, 2013 13:33
how to send data with + in javascript
<script type="text/javascript">
$.ajax({
type: 'POST',
cache: false,
data: 'params=' + escape(JSON.stringify(structure)).replace(new RegExp("\\+", "g" ),"%2B"),
url: '/adm.php/sendregexp',
success: function(response) {
var result = jQuery.parseJSON(response);
if (result.code == 300) {
@stajnert
stajnert / changeConnection.php
Last active December 15, 2015 23:59
Chane connection with db - symfony 1.4
<?php
// connect with other database
// $instance - object with new database data
new sfDoctrineDatabase(array(
'name' => 'instance',
'dsn' => 'mysql:host=' . $instance->getInstanceDbHost() . ';dbname=' . $instance->getInstanceDbName(),
'username' => $instance->getInstanceDbUser(),
'password' => $instance->getInstanceDbPassword(),
));
@stajnert
stajnert / getFirst.php
Created April 2, 2013 08:33
Get records first by slug = london, then rest
<?php
$this->locations = Doctrine_Core::getTable('location')
->createQuery('l')
->orderBy("CASE url_slug WHEN :slug THEN '' ELSE name END")
->execute(array('slug' => 'london'));
>?
@stajnert
stajnert / .htaccess
Created April 2, 2013 07:15
Enable gzip compression on the fly
#Gzip
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript text/javascript
</ifmodule>
#End Gzip
@stajnert
stajnert / size.sql
Created March 18, 2013 09:46
db size
SELECT table_schema,
CONCAT(ROUND(SUM(data_length/(1024*1024)),2),'M') data,
CONCAT(ROUND(SUM(index_length/(1024*1024)),2),'M') idx,
CONCAT(ROUND((SUM(data_length+index_length)/(1024*1024)),2),'M') total_size
FROM information_schema.tables
GROUP BY table_schema
ORDER BY data_length+index_length DESC;
SHOW TABLE STATUS FROM etracker;
@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')
@stajnert
stajnert / integer.js
Last active December 13, 2015 23:48
Fetch integer from attr
var int = $(this).attr('id').match(/\d+/);
@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 / 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