Skip to content

Instantly share code, notes, and snippets.

View jbinfo's full-sized avatar

Lhassan Baazzi jbinfo

View GitHub Profile
@jbinfo
jbinfo / all_form_errors.macro.twig
Last active December 12, 2015 06:49
TWIG macro for display all Symfony2 form errors in your template
{#
this macro is for display all form errors(globals, fields errors)
@param is_global have two values 1 and 2
1 => for a global error
2 => for a field error
#}
{% macro all_form_errors(form, is_global) %}
{% set is_global = is_global|default(1) %}
{% for error in form.get('errors') %}
<span style="display: block">

Copied from http://code.lancepollard.com/complete-list-of-html-meta-tags/

Basic HTML Meta Tags

<meta charset='UTF-8'>
<meta name='keywords' content='your, tags'>
<meta name='description' content='150 words'>
<meta name='subject' content='your website's subject'>
<meta name='copyright' content='company name'>
@jbinfo
jbinfo / scrapy_csv_exporter.md
Last active March 7, 2022 05:49
How to create a Scrapy CSV Exporter with a custom delimiter and order fields

Create a scrapy exporter on the root of your scrapy project, we suppose the name of your project is my_project, we can name this exporter: my_project_csv_item_exporter.py

from scrapy.conf import settings
from scrapy.contrib.exporter import CsvItemExporter

class MyProjectCsvItemExporter(CsvItemExporter):

    def __init__(self, *args, **kwargs):
 delimiter = settings.get('CSV_DELIMITER', ',')

Multiple PHP version under Ubuntu 14.04

Update your machine

apt-get update
apt-get upgrade

Install some dependencies

apt-get install build-essential

@jbinfo
jbinfo / urlparse.py
Last active August 29, 2015 14:08 — forked from zhenyi2697/urlparse.py
#!/usr/bin/python
# The urlparse module provides functions for breaking URLs down into their
# component parts, as defined by the relevant RFCs.
from urlparse import urlparse
# PARSING
parsed = urlparse('http://user:pass@NetLoc:80/path;parameters?query=argument#fragment')
@jbinfo
jbinfo / auto_twitter_follow_script.js
Last active February 5, 2023 04:03
auto twitter follow script
;(function(global, $) {
/**** PARAMETERS BLOCK ************************/
var miniFollowersToIgnore = 0,
miniFollowingToKeep = 1000,
secondes = Math.floor((Math.random() * 10) + 10),
enableBioFilter = false,
userBioKeywords = [
'devel', 'code', 'analysis',
'cloud', 'unix', 'tech', 'computer',
'.net', 'freelance', 'guru', 'UX',
var getYoutubeIdByUrl = function( url ){
var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
var match = url.match(regExp);
if(match&&match[7].length==11){
return match[7];
}
return false;
};
@jbinfo
jbinfo / Preferences.sublime-settings
Created July 23, 2015 07:36
Preferences.sublime-settings
{
"trim_trailing_white_space_on_save": true,
"ensure_newline_at_eof_on_save": true,
"word_wrap": false,
"color_scheme": "Packages/Github Color Theme/GitHub.tmTheme",
"ignored_packages":
[
"Vintage"
]
}
@jbinfo
jbinfo / gist:ce5600eb7ea276dc194c
Created December 16, 2015 15:11 — forked from serapheem/gist:4153979
Symfony2 - Redirect one route to another from routing.yml
SomeRoute:
pattern: /someroute
defaults:
_controller: SomeBundle:Controller:action
AnotherRoute:
pattern: /anotherroute
defaults:
_controller: FrameworkBundle:Redirect:redirect
route: SomeRoute
@jbinfo
jbinfo / closespider.py
Last active June 7, 2019 06:40
CloseSpider is a Scrapy extension that force spider to be closed after it reach a drop items limit
# -*- coding: utf-8 -*-
# MIT License (c) Lhassan Baazzi <baazzilhassan@gmail.com>
from collections import defaultdict
from twisted.internet import reactor
from scrapy import signals
class CloseSpider(object):
def __init__(self, crawler):