Skip to content

Instantly share code, notes, and snippets.

@Soraph
Soraph / htaccess_ie-edge_chromeframe
Created September 13, 2013 13:04
.htaccess instruction to force the use of the latest IE version or ChromeFrame if is present
<IfModule mod_headers.c>
Header append X-UA-Compatible "IE=edge,chrome=1"
<FilesMatch "\.(appcache|crx|css|eot|gif|htc|ico|jpe?g|js|m4a|m4v|manifest|mp4|oex|oga|ogg|ogv|otf|pdf|png|safariextz|svg|svgz|ttf|vcf|webm|webp|woff|xml|xpi)$">
Header unset X-UA-Compatible
</FilesMatch>
</IfModule>
@Soraph
Soraph / template.php
Last active December 22, 2015 23:59
Drupal 7 theme function to update the jQuery version used by the website, strongly recommended to restrict this to specific URLs, it will create issues in the default administration theme. More info: http://oldwildissue.wordpress.com/2012/11/19/drupal-7-manually-update-jquery-version/
<?php
function yourtheme_js_alter(&$javascript) {
[...]your stuffs[...]
$jquery_new = drupal_get_path('theme','yourtheme') . '/js/jquery-1.10.2.min.js';
$javascript[$jquery_new] = $javascript['misc/jquery.js'];
$javascript[$jquery_new]['version'] = '1.10.2';
$javascript[$jquery_new]['data'] = $jquery_new;
@Soraph
Soraph / template.php
Created September 17, 2013 15:53
Removing CSS in Drupal 7 with hook_css_alter(&$css)
<?php
function yourtheme_css_alter(&$css){
$to_be_removed = array('sites/all/modules/example_module/styles/example_module_css.css' => FALSE,);
$css = array_diff_key($css,$to_be_removed);
}
@Soraph
Soraph / styles.css
Created September 25, 2013 08:34
Using generic font-family to have consistency across operative systems http://www.w3.org/TR/CSS2/fonts.html#generic-font-families
pre {
font-family: monospace;
white-space: pre-wrap; /* css-3 */
white-space: -moz-pre-wrap; /* Mozilla */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: -o-pre-wrap; /* Opera 7 */
word-wrap: break-word; /* Internet Explorer 5.5+ */
/*
padding: XX;
margin: XX;
@Soraph
Soraph / my.module
Created October 10, 2013 14:09
Example for Tushar
function my_menu() {
$items['path/page'] = array(
'title' => t('Page title'),
'page callback' => 'mypage_callback_function',
'page arguments' => array('my','totally','optional','argumet','list'),
);
return $items;
}
// All your other module logic
@Soraph
Soraph / environment.rb
Created October 29, 2013 09:09
field_error_proc override to add the "has-error" class
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
if html_tag.match(/class=(\'|\")([\w\s\d]*?)\1/i)
html_tag.gsub(/class=(\'|\")([\w\s\d]*?)\1/i, 'class="\2 has-error"')
else
html_tag.gsub(/\<[\w]+/i, '\0 class="has-error"')
end
end
@Soraph
Soraph / magicelements.css
Created March 24, 2014 11:53
Highlight each element on the page
/*
Source: http://b.qr.ae/1rmTvEY
*/
* { background-color: rgba(255,0,0,.2); }
* * { background-color: rgba(0,255,0,.2); }
* * * { background-color: rgba(0,0,255,.2); }
* * * * { background-color: rgba(255,0,255,.2); }
* * * * * { background-color: rgba(0,255,255,.2); }
* * * * * * { background-color: rgba(255,255,0,.2); }
@Soraph
Soraph / template.php
Last active August 29, 2015 13:59
Add a custom CSS class to an image in Drupal 7
<?php
function fancythemename_preprocess_image(&$variables) {
if (isset($variables['style_name'])) {
if ($variables['style_name'] == 'fancystylename')
$variables['attributes']['class'][] = 'img-thumbnail'; //bootstrap class
}
}
@Soraph
Soraph / soraph_range.js
Last active September 11, 2017 14:14
Range function for JavaScript
const sRange = (from, to, includeUpperLimit = false) => {
/*
* Params:
*
* from: integer, first value of cycle and the Array
* to: integer, last value of the cycle
* includeUpperLimit: boolean, if true will use to as last
* element of the Array
*
* Works like Python's range() but two params are mandatory.
#!/bin/bash
#Author: Matteo Canu <soraph88@gmail.com>
# Handy script to resize and optimize image size.
# Version 0.2.1
# 2020-02-07: Linting and cleanup
wkpath=