Symfony 2 date widget (jquery) with angular

Override twig’s default rendering of date widget by following the steps explained here: Twig Form Templating

//twig template
{% block date_widget %}
    {% spaceless %}
        {% if widget == 'single_text' %}
            {% spaceless %}
                {% set type = type|default('text') %}
                <input type="{{ type }}" value="{{ value }}" data-date-picker="" />             
            {% endspaceless %}
        {% else %}
{{ date_pattern|replace({ '{{ year }}': form_widget(form.year), '{{ month }}': form_widget(form.month), '{{ day }}': form_widget(, })|raw }}
{% endif %} {% endspaceless %} {% endblock %}

And angular code(can be easily extended to work with any other library like bootstrap):

directive_app.directive('datePicker', function () {
    return function (scope, element, attrs) {
        var fmt = (attrs.format != 'undefined') ? attrs.format : 'yy/mm/dd'; //supports defining date format through property like <input type="text" data-format="your_format" />
        element.datepicker({ dateFormat: fmt });

And define your symfony date widget as:

    $builder->add('data', 'date', array('widget' => 'single_text', 'format' => 'your_format'));

Angular autocomplete directive with custom field names

A short example of using jquery’s autocomplete with angularjs. Code needs some optimization.

directive_app.directive('autoComplete', function ($timeout) {
    return function (scope, element, attrs) {
            minLength: 1,
            source: function (request, response) {
                var matcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), "i");
                var mapper = $.map(scope[attrs.uiItems], function (item) {
                    return {
                        label: item.custom_field_name,
                        value: item.custom_field_name,
                response($.grep(mapper, function (value) {
                    return matcher.test(value.label);
            select: function (event, ui) {
                $timeout(function () {
                }, 0);

                if (attrs.updateModelOnSelect) {
                    scope.$apply(function () {
                        scope[attrs.updateModelOnSelect] = ui.item;
        }).data("ui-autocomplete")._renderItem = function (ul, item) {
            return $("<li>")
                .append("<a>" + item.label + "</a>")

Example usage:

<input type="text" autocomplete="off" data-auto-complete="" data-ui-items="controller_scope_var_to_get_data_from" data-update-model-on-select="controller_scope_var_to_put_selected_item" />

Evaluating scope variables inside ng-repeat with handcrafted html

var directive_app = angular.module('dx.directives', []);
var service_app = angular.module('', []);
var filter_app = angular.module('dx.filters', []);
var app = angular.module('dx', ['ngResource', 'dx.directives', '', 'dx.filters'], function ($compileProvider) {
    $compileProvider.directive('compile', function ($compile) {
        return function (scope, element, attrs) {
                function (scope) {
                    return scope.$eval(attrs.compile);
                function (value) {

And in your template:

<tr data-ng-repeat="iesire in iesiri">
     <td data-compile="template"></td>

Further reading:$compile

CookieContainer’s cookies not being sent

Consider the following scenario:

You have a web service that you want to access with a  login url like this: http://subdomain.domain/login.php?checklogin=true, that sets a cookie after a succesful login, using Set-Cookie header without a path. Further you want to access a page like http://subdomain.domain/someservice.php.

Now with .NET you would do something like

CookieContainer cookies = new CookieContainer();

HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri("http://subdomain.domain/login.php?checklogin=true"));

request.CookieContainer = cookies;


HttpWebRequest resource_request = (HttpWebRequest)HttpWebRequest.Create(new Uri("http://subdomain.domain/someservice.php"));

resource_request.CookieContainer = cookies;

Now on the second request you’ll see that your cookies are not being sent. That’s because the path for the cookies sent in the login page get the path of the original Uri which is “http://subdomain.domain/login.php”. One of the possible fixes would be calling the following function after the login request:

public static void AbsoluteCookies(ref CookieContainer cookie_container, Uri uri)
CookieCollection cookies = cookie_container.GetCookies(uri);

foreach (Cookie cookie in cookies)
cookie.Path = "/";



The above will become:

CookieContainer cookies = new CookieContainer();

HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri("http://subdomain.domain/login.php?checklogin=true"));

request.CookieContainer = cookies;

AbsoluteCookies(ref cookies, request.RequestURI);


HttpWebRequest resource_request = (HttpWebRequest)HttpWebRequest.Create(new Uri("http://subdomain.domain/someservice.php"));

resource_request.CookieContainer = cookies;

Now the second request should get the cookies that were set in the initial request(login page).

Samsung Kies 2 not opening

You may experience a weird behaviour after installing the latest version of Samsung Kies, when running on a regular user (non administrator account). The program will refuse to launch. That’s because you need to run Kies as an computer administrator. Right click the Kies icon, and click Run as administrator, input your password (if any) and the program should now launch.

Getting datagridviewcomboboxcell default selected item value

Consider a following scenario: You have a datagridview bound to a datasource and you need to add one new combo box column with some values that are not linked to the bound datasource from which the user has to selected some values or simply approve them. You also need to get some preselected value in every combobox cell. Now setting the Value property of the datagridviewcomboboxcell with give you a string not the object itself, meaning that setting something like this mydatagridviewcomboboxcell.Value = myObject; will return you a string not myObject. However if the user selects a value from the dropdown the value will be set to a myobject instance. You can use this in your advantage, getting the the “default” selected value like this: if(mydatagridviewcomboboxcell.getType() == String) {//no user interaction here, the default value of the cell is selected and you can grab it from first item of the combo for example mydatagridviewcomboboxcell.Items[0] as myobject } else { //the user edited this cell and we have a value of type myobject }

Change page orientation in Lion

defaults write UserDefaultPageFormat -dict-add -integer 2

or using applescrip

do shell script “defaults write UserDefaultPageFormat -dict-add -integer 2″

the value after -integer can be 1,2 or 3:

1: Portrait

2: Landscape

3: Reversed landscape

SVN checkout failed

Normally this error occurs when you’re running under some sort of proxy environment. The fix is pretty simple:

Open a terminal window:

type sudo pico ~/.subversion/servers

scroll down until you find the [global] line (should be at the end of the file) and uncomment if commented (aka preceded by ###) the following lines:

http-proxy-host = your_proxy_address
http-proxy-port = your_proxy_port
http-proxy-username = your_proxy_user
http-proxy-password = your_proxy_pass
http-compression = no

Compile parameters for php 5.3.10 under MacOS Lion

MacPorts for latest libpng, iconv and openssl libraries

./configure \
–prefix=/usr/local \
–with-apxs2=/usr/sbin/apxs \
–with-ldap=/usr \
–with-kerberos=/usr \
–enable-cli \
–with-zlib-dir=/usr \
–enable-exif \
–enable-ftp \
–enable-mbstring \
–enable-mbregex \
–enable-sockets \
–with-iodbc=/usr \
–with-curl=/usr \
–with-config-file-path=/etc \
–sysconfdir=/private/etc \
–with-mysql=mysqlnd \
–with-mysqli=mysqlnd \
–with-pdo-mysql=mysqlnd \
–with-openssl=/usr \
–with-xmlrpc \
–with-xsl=/usr \
–without-pear \
–with-libxml-dir=/usr \
–with-iconv-dir=/usr/local \
–with-gd \
–with-jpeg-dir=/opt/local \
–with-png-dir=/opt/local \
–with-freetype-dir=/opt/local \