Skip to content

Instantly share code, notes, and snippets.

@shmaltorhbooks
shmaltorhbooks / footer.php
Created July 2, 2014 13:39
XHProf header/footer
@shmaltorhbooks
shmaltorhbooks / layout.html.twig
Last active August 29, 2015 14:03
fos js routing
<script type="text/javascript" src="{{ asset('/bundles/fosjsrouting/js/router.js') }}"></script>
{% if _env == 'prod' %}
<script type="text/javascript" src="{{ asset('/js/fos_js_routes.js') }}"></script>
{% else %}
<script type="text/javascript" src="{{ path('fos_js_routing_js', {"callback": "fos.Router.setData"}) }}"></script>
{% endif %}
<?php
$filter = 'foo';
$qb = $this->getEntityManager()->createQueryBuilder();
$qb->select('u');
$qb->from($this->getClassName() , 'u');
$qb->add('where', $qb->expr()->orx(
$qb->expr()->like('u.email', $qb->expr()->literal('%'.$filter.'%')),
@shmaltorhbooks
shmaltorhbooks / sf2.sh
Last active August 29, 2015 14:00
init sf2 application on deploy
#!/bin/sh
echo "cache..."
php app/console cache:clear --env=dev
php app/console cache:clear --env=prod
echo "doctrine..."
php app/console doctrine:cache:clear-metadata
@shmaltorhbooks
shmaltorhbooks / config.yml
Last active August 29, 2015 13:59
create session shared with Symfony2
services:
session.metadata_bag:
class: Symfony\Component\HttpFoundation\Session\Storage\MetadataBag
arguments:
- '_sf2_meta'
- '0'
public: false
session.file_handler:
class: Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeFileSessionHandler
arguments:
http {
map $http_user_agent $limit_bots {
default '';
~*(google|bing|yandex|msnbot) $binary_remote_addr;
}
limit_req_zone $limit_bots zone=bots:10m rate=1r/m;
server {
alias l='ls -alF'
alias la='ls -A'
alias ll='ls -CF'
alias gittree='git log --pretty=format:"%h - %an, %ar : %s" --graph'
Article:
manyToMany:
tags:
targetEntity: Tag
inversedBy: articles
joinTable:
name: tags_for_articles
joinColumns:
article_id:
referencedColumnName: id
@shmaltorhbooks
shmaltorhbooks / generate_ssl_nginx.sh
Created December 10, 2013 10:41
generate self-signed ssl certificates for nginx
sudo mkdir /etc/nginx/ssl && cd /etc/nginx/ssl
sudo openssl genrsa -des3 -out server.key 1024
sudo openssl req -new -key server.key -out server.csr
sudo cp server.key server.key.org
sudo openssl rsa -in server.key.org -out server.key
sudo openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
echo "add these lines into your nginx host config"
echo " ssl on;"
echo " ssl_certificate /etc/nginx/ssl/server.crt;"
echo " ssl_certificate_key /etc/nginx/ssl/server.key;"
@shmaltorhbooks
shmaltorhbooks / number.php
Last active December 18, 2015 00:59
Add (th, st, nd, rd, th) to the end of a number
<?php
function ordinal($cdnl){
$test_c = abs($cdnl) % 10;
$ext = ((abs($cdnl) %100 < 21 && abs($cdnl) %100 > 4) ? 'th'
: (($test_c < 4) ? ($test_c < 3) ? ($test_c < 2) ? ($test_c < 1)
? 'th' : 'st' : 'nd' : 'rd' : 'th'));
return $cdnl.$ext;
}