Skip to content

Instantly share code, notes, and snippets.

@Soraph
Soraph / haproxy.cfg
Created July 28, 2023 14:36
Out of the box default configuration file for haproxy-1.8.27-5.el8.x86_64
#---------------------------------------------------------------------
# Example configuration for a possible web application. See the
# full configuration options online.
#
# https://www.haproxy.org/download/1.8/doc/configuration.txt
#
#---------------------------------------------------------------------
#---------------------------------------------------------------------
# Global settings
@Soraph
Soraph / clean_repo.sh
Created November 16, 2022 14:36
Repo maintenance, be sure to not have things in stash
git fetch --prune
git branch -vv | grep -i 'gone' | awk '{print $1}' | xargs git branch -D
git fsck --full
git reflog expire --expire=now --all
git repack -a -d -l
git gc --prune=now --aggressive
#!/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=
@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.
@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 / 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 / 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 / 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 / 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 / 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);
}