Skip to content

Instantly share code, notes, and snippets.

View gabrielmansour's full-sized avatar

Gabriel Mansour gabrielmansour

View GitHub Profile
@gabrielmansour
gabrielmansour / generator.js
Created July 5, 2014 06:25
Sex T-Rex Cowboy quote generator
// Quote generator for
// http://sextrexcomedy.com/2013/07/23/cowboy-quote-generator/
// Outputs a list of quotes. Choose your favourite and make it an image macro!
function generateQuote(){
for (var $rows=jQuery('table tr'), numrows=$rows.length, phrase=[], i=2;i<=4;i++){
phrase.push( $rows.eq( ~~(Math.random() * numrows) ).find('td:nth-child('+i+')').text().trim() );
}
return phrase.join(' ');
}
def rot13(word)
alphabet = ('a'..'z').to_a
word.downcase.split('').map do |letter|
index = alphabet.index(letter)
if index >= 13
index -= 13
else
index += 13
end
alphabet[index]
@gabrielmansour
gabrielmansour / gist:9843631
Created March 28, 2014 21:45
HTML entities escape-once regex
// Does not match against already-encoded HTML entities (e.g. &amp;)
/&(?!(?:[a-z0-9]+|#x?[a-z0-9]{1,4});)/i
@gabrielmansour
gabrielmansour / gist:8969418
Last active August 29, 2015 13:56
CONVENT CONNIVANCE CONFUDDLES CONSTABLES:
CONVENT CONNIVANCE CONFUDDLES CONSTABLES:
Considering conspicuous conduct concerning constant congregation confessions, Contra-Conformists confident
Conservative congressmen conversion conspiracy continues, constructing contrived convivial consecrations
connecting controversial contretemps. Consequently, consistent concentrated conflict convulses Connecticut;
Confederates' condos condemned.
var a = [];
for (var i in localStorage){
if (localStorage.propertyIsEnumerable(i) && i.indexOf('dataset_')===0){
a.push( i.split('_')[1] );
}
}
$('#container').load([location.path, a.join('|')].join('/'));
// Convert CamelCase to an under_scored_word
function underscore(s){
return s.replace(/(?!^)([A-Z])/g, function(m){ return '_' + m }).toLowerCase();
}
<?php
static function present($object){
$klass= ucfirst(preg_replace_callback('/_([a-z])/',
function($m) { return strtoupper($m[1]);},
$object->type)). 'Presenter';
return new $klass($object);
}
@gabrielmansour
gabrielmansour / drupal_var_fix.php
Created November 27, 2013 19:34
Identify any unserialization issues in Drupal to we can resolve them
#!/usr/bin/env drush
# Once it prints the faulty variable names, just re-set the values using `drush vset {variable_name} "{value}"
$variables = db_query('SELECT name, value FROM {variable}')->fetchAllKeyed();
foreach ($variables as $key => $val) {
$v = unserialize($val);
if ($v === FALSE && $val !== 'b:0;') {
@gabrielmansour
gabrielmansour / gist:6833135
Last active December 24, 2015 17:09
Styled numbered bullets.
div { font-family: Helvetica, Arial, sans-serif; width: 50%;}
ol li {
list-style-type: none;
counter-increment: li;
margin-bottom: 0.5em;
margin-left: 3em;
}
ol li:before {
content: counter(li);
position: relative;
@gabrielmansour
gabrielmansour / css_URIs.js
Last active December 23, 2015 09:29
Get a list of stylesheet paths for an HTML document.
$.each(document.styleSheets, function() {
this.href ? console.log(this.href) : $.map(this.cssRules, function(import){ console.log(import.href) })
})