Skip to content

Instantly share code, notes, and snippets.

View gabrielmansour's full-sized avatar

Gabriel Mansour gabrielmansour

View GitHub Profile
@gabrielmansour
gabrielmansour / gist:6208002
Last active September 9, 2021 09:30
ExpressionEngine to WordPress WXR template
<?php
// EE to WP Export template
// Run at http://site.com/template-location/CHANNEL_NAME/POST_TYPE/CONTENT_FIELD_NAME/FEATURED_IMAGE_FIELD_NAME/OFFSET
// It's important to use a root level template, and restrict access to the admin role
// Set Type to XML, allow PHP, and PHP Parse on Output
$DB = &$this->EE->db;
echo '<' . '?' . 'xml version="1.0" encoding="UTF-8"' . '?' . '>';
?>
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) })
})
@gabrielmansour
gabrielmansour / hack sink ship
Last active December 19, 2015 13:09 — forked from cwsaylor/gist:8511
hack sink ship
# Variation on Hashrocket's script for managing the git process
# as documented here: http://reinh.com/blog/2008/08/27/hack-and-and-ship.html
# Create shell scripts out of each of these, put them in your path (~/bin for example)
# chmod 755 them and use like this:
#
# This version of hack is totally different than Hackrockets. I feel that hack implies
# that you are getting started, not finishing up. sink is Hashrockets hack.
#
# $ hack branch_name
# Test and Implement until done
@gabrielmansour
gabrielmansour / fizzbuzz2.rb
Created June 7, 2013 00:06
The solution to a modified version of the FizzBuzz challenge.
# Given a number, write a method that outputs the following:
# when a multiple of 3, output "appy"
# when a multiple of 5, output "fizz"
# when a multiple of 3 and 5, output "appy-fizz"
# Otherwise, output "I'm all good here."
def appyfizz(n)
s = []
s << "appy" if n % 3 == 0
s << "fizz" if n % 5 == 0
$fib = Hash.new { |_,n| n < 2 ? n : $fib[n-1] + $fib[n-2] }
def fibsequence(n)
(0...n).map{ |i| $fib[i] }.join(',')
end
100.times do |i|
puts [i, fibsequence(i)].join(' - ')
end