Skip to content

Instantly share code, notes, and snippets.

View tacone's full-sized avatar
💭
¯\_(ツ)_/¯

tacone

💭
¯\_(ツ)_/¯
View GitHub Profile
@tacone
tacone / gist:4534615
Last active December 11, 2015 02:58
How to manage structured data with Bootstrap typeahead.
/* bad indentation is NetBeans' fault, camelCase is Propel's fault */
var retrieveTeachers = function(query, process) {
// let them be json
var transformTeachers = function(teachers) {
return $.map(teachers, function(teacher) {
return {
id: teacher.Id,
FullName: (teacher.Name + ' ' + teacher.Surname),
// these functions allows Bootstrap typehead to use this item in places where it was expecting a string
toString: function() {
@tacone
tacone / bootstrap-dropdown-close-wtf.js
Last active December 16, 2015 06:09
How to know when a Bootstrap dropdown has been closed, even if it supports no events
/*
* Quorque tu, @fat.
* https://github.com/twitter/bootstrap/issues/1343
*/
$('[data-toggle=dropdown]').click(function() {
var parent = $(this).parent();
if (!parent.hasClass('open') && parent.data('close-callback'))
{ //sta per aprirsi
parent.data('has-been-opened', true);
}
@tacone
tacone / bool-search-button.js
Last active December 17, 2015 07:49
Boolean field for a search box: Sample progressive enhancement boolean Selectbox (null, true, false) to 3-state-button using jQuery and Bootstrap. Case use: an advanced search box, with boolean fields allowing to either filter by true, false or not filter at all.
+function() {
var buttons = $('.container select').map(function() {
var $select = $(this);
var $options = $select.find('option');
var $button = null;
var updateUi = function() {
var normalizedVal = $select.val() != '' ? parseInt($select.val()): null;
switch (normalizedVal)
{
case null:
@tacone
tacone / quick-palette.php
Created May 15, 2013 09:53
Quick palette
<?php
$palette = array(
'#DE3645','#F58759','#FBE25E','#B8D246','#129A77','#9CC3AD',
'#7DA1BF','#114477','#B086B9','#FAE1CB','#CAC4AE','#989899',
'#EBAE45', '#F58343'
);
// in a cycle
$count = 0;
foreach ($answers as $a)
@tacone
tacone / firebug-compat.js
Created June 3, 2013 12:19
Firebug compat for IE
if (!console)
{
var console = {};
console.turnOff = function()
{
var api = ['log', 'debug', 'info', 'warn', 'error', 'assert', 'dir', 'dirxml', 'trace', 'group', 'groupEnd', 'time', 'timeEnd', 'profile', 'profileEnd', 'count'];
for (var i = 0; i < api.length; i++)
console[ api[i] ] = function() {
};
console.firebug = "0.00";
@tacone
tacone / ubuntu-install-tidy-html5.sh
Last active December 11, 2016 01:26
Install html5 tidy on ubuntu as a deb package
#!/bin/bash
# Check if user is root
if [ $(id -u) != "0" ]; then
echo "Error: You must be root to run this script, please use root to install the software."
exit 1
fi
apt-get remove libtidy-0.99-0 tidy
apt-get install git-core automake libtool checkinstall
@tacone
tacone / gist:7601462
Created November 22, 2013 15:13
Quick file extension
<?php
$file_extension=".".strtolower(pathinfo($_FILES["Filedata"]["name"],PATHINFO_EXTENSION));
@tacone
tacone / rewriteProperties.js
Last active August 29, 2015 13:57
How to interpolate/evaluate javascript object keys
/**
* Will evaluate all the keys of a given object containing a plus sign "+"
* to the expression result.
*
* example:
* var a = 2;
* var obj = { " 'hello' + a " : true };
* rewriteProperties(obj); // returns { hello2: true }
*
*/
@tacone
tacone / gist:8f270be8814c107399e5
Created July 27, 2014 14:08
Print a Baum tree with Twig
{% macro menuLinks(root, maxdepth) %}
{% import _self as macros %}
{# print a UL tree #}
{% for link in root.children %}
<li>
<a href="{{ link.slug }}">{{ link.name }}</a>
{% if link.children and (maxdepth > link.depth or not maxdepth) %}
<ul>
{{ macros.menuLinks(link, maxdepth) }}
</ul>
@tacone
tacone / wwwwrite.zsh
Last active August 29, 2015 14:05
Give the webserver write permissions on a folder
function wwwwrite () {
sudo setfacl -R -m u:www-data:rwX -m u:`whoami`:rwX $1 && sudo setfacl -dR -m u:www-data:rwx -m u:`whoami`:rwx $1
}