/ Gists

Gists

On gists

curl POST examples

PHP

server.js #

var app = require('express')();
var bodyParser = require('body-parser');

app.use(bodyParser.json()); // for parsing application/json
app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded

app.post('/data', function (req, res) {
  console.log(req.body);
  res.end();
});

app.listen(3000);

On gists

404 In presenter

Nette

SomePresenter.php #

			$this->getHttpResponse()->setCode(\Nette\Http\Response::S404_NOT_FOUND);
			$this->setView('missing');

On gists

Nette - conditions - retezení

Nette Nette-Forms

example.php #

<?php

1) 
$videoLength = $video->addText('videoLength', 'Délka videa');
$videoLength->addConditionOn($form['article-published'], Form::EQUAL, TRUE)
    ->setRequired();
$videoLength->addCondition(Form::FILLED)
    ->addRule(Form::PATTERN
    
    


2)
$video->addText('videoLength', 'Délka videa')
    ->addConditionOn($form['article-published'], Form::EQUAL, TRUE)
    ->setRequired()
    ->endCondition()
    ->addCondition(Form::FILLED)
    ->addRule(Form::PATTERN, 'Délka musí být zadána ve formátu minuty:sekundy', '[0-9]+:[0-9]{2}');

On gists

Nette - conditions -

Nette Nette-Forms

lambda.php #

<?php

->addCondition(function() use ($form) {
    return ...; //true nebo false
})

On gists

Nette - fileupload from URL

Nette Nette-Forms

fileupload.php #

<?php

$fileUpload = new \Nette\Http\FileUpload([
    'name' => basename($filePath),
    'size' => filesize($filePath),
    'tmp_name' => $filePath,
    'error' => UPLOAD_ERR_OK,
]);

On gists

JS Bin Rating panel via CSS 3 & jQuery // source http://jsbin.com/denukot

jQuery

jsbin.denukot.js #

$('#wrapper div').mouseover(function(){
	
	
	$(this).children('span').addClass('active');
	$(this).prevAll().children('span').addClass('active')
	
});

$('#wrapper div').mouseout(function(){
	
	
$(this).prevAll().children('span').removeClass('active')
		$(this).children('span').removeClass('active');
	
});

On gists

Triggers example

MySql

triggers-example.sql #


CREATE TRIGGER trRaiseTopicCountAll
AFTER INSERT ON forum_commentary
FOR EACH ROW 
BEGIN    
    UPDATE forum_topic 
    SET forum_commentary_count_all = @forum_commentary_count_all +1 
    WHERE forum_topic_id = NEW.forum_topic_id;
    IF (NEW.commentary_parent_id IS NULL) 
        THEN 
            UPDATE forum_topic 
            SET first_commentary_id = NEW.forum_commentary_id 
            WHERE forum_topic_id = NEW.forum_topic_id;
    END IF; 
END;
    
    
CREATE TRIGGER trRaiseTopicCountVisible
AFTER UPDATE ON forum_commentary
FOR EACH ROW 
BEGIN    
    IF (OLD.forum_commentary_status_id <> NEW.forum_commentary_status_id)
        THEN 
            IF (NEW.forum_commentary_status_id = 2) 
            THEN 
                UPDATE forum_topic 
                SET forum_commentary_count_visible = @forum_commentary_count_visible +1 
                WHERE forum_topic_id = NEW.forum_topic_id;
            ELSE 
                UPDATE forum_topic 
                SET forum_commentary_count_visible = @forum_commentary_count_visible -1 
                WHERE forum_topic_id = NEW.forum_topic_id;
            END IF;    
    END IF;
END;

On gists

Adweb component template config

Nette

some-component-default.latte #

	{control footerContactForm templateConfig => ['btn_contact_form' => $data->btn_contact_form != '' ? $data->btn_contact_form : 'Odeslat dotaz']}

On gists

JS constructor + init immediately

JavaScript-OOP JavaScript

demo.js #

1)
var Abc = function(aProperty,bProperty){
    this.aProperty = aProperty;
    this.bProperty = bProperty;
    this.init = function(){
        // Do things here.
    }
    this.init();
}; 
var currentAbc = new Abc(obj,obj);


2)
var Abc = function(aProperty,bProperty){
   function privateInit(){ console.log(this.aProperty);}   
   this.aProperty = aProperty;
   this.bProperty = bProperty;

   privateInit.apply(this);
};


3)
var Abc = function(aProperty,bProperty){
    this.aProperty = aProperty;
    this.bProperty = bProperty;

    //init
    (function () {
        // Perform some operation
    }.call(this));
}; 
var currentAbc = new Abc(obj,obj);

On gists

Multiple animation with one finish callback

jQuery

demo.js #

$(document).ready(function () {
    animate([$('#one'), $('#two'), $('#three')], finished);
});

function finished() {
    $('body').append('Finished');
}

function animate(list, callback) {
    if (list.length === 0) {
        callback();
        return;
    }
    $el = list.shift();
    $el.animate({left: '+=200'}, 1000, function () {
        animate(list, callback);
    });
}