Skip to content

Instantly share code, notes, and snippets.

@josephmosby
josephmosby / sample.info
Created October 30, 2014 15:37
Sample Drupal .info file
name = Sample
description = A Sample theme.
core = 7.x
stylesheets[all][] = css/bootstrap.min.css
stylesheets[all][] = css/bootstrap-theme.min.css
stylesheets[all][] = css/style.css
scripts[] = JS/bootstrap.min.js
@josephmosby
josephmosby / render.html
Last active August 29, 2015 14:08
A snippet of code showing how Drupal renders a block
<div class="wrapper header-wrapper">
<div class="container" id="top_menu">
<div class="row">
<div class="col-md-6">
<div class="region region-sm-icons-top">
<div id="block-block-5" class="block block-block">
<div class="content">
<ul><li><a href="/social-media"><img src="/sites/all/themes/base/images/facebook.png"></a></li>
<li><a href="/social-media"><img src="/sites/all/themes/base/images/twitter.png"></a></li>
<li><a href="/social-media"><img src="/sites/all/themes/base/images/instagram.png" width="26" height="26"></a></li>
@josephmosby
josephmosby / tpls.php
Last active August 29, 2015 14:10
TPLS
/* FOR LE TEMPLATE.PHP
/* THIS CODE CALLS A CUSTOM PAGE.TPL FILE IF YOU HAVE A SPECIFIC CONTENT TYPE
function plstwo_preprocess_page(&$vars) {
if (isset($vars['node']->type)) {
$vars['theme_hook_suggestions'][] = 'page__' . $vars['node']->type;
}
}
/* --------------- */
@josephmosby
josephmosby / working_video.html
Created December 10, 2014 18:51
A snippet of code to launch a hosted MP4 video that will auto play in all browsers, including IE8.
<!DOCTYPE html>
<html>
<head>
<!-- use Modernizr and Video.js for cross browser compatibility -->
<meta http-equiv="X-UA-Compatible" content="IE=Edge"/>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.min.js"></script>
<link href="//vjs.zencdn.net/4.11/video-js.css" rel="stylesheet">
</head>
<body>
<!-- for Video.js, the ID and class attributes are needed.
@josephmosby
josephmosby / embed.html
Created December 16, 2014 14:35
An embed for a friendly holiday e-card
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge"/>
</head>
<body>
<iframe width="800" height="600" src="EMBED CODE HURR" frameborder="0" allowfullscreen></iframe>
</body>
</html>
@josephmosby
josephmosby / ocheck.js
Created February 23, 2015 20:17
Low-grade check for equality between two JavaScript objects
Object.prototype.equals = function(object) {
if (Object.keys(this).length != Object.keys(object).length) {
return false;
}
for (var i = 0; i < Object.keys(this).length; i++) {
if (this[Object.keys(this)[i]] != object[Object.keys(object)[i]]) {
return false;
}
}
@josephmosby
josephmosby / indexAll.js
Created March 20, 2015 19:43
Index everything in a MongoDB collection
db.system.js.save(
{
_id: "indexAll",
value: function() {
colls = db.getCollectionNames();
for (var i = 0; i < colls.length; i++) {
if (colls[i] != "system.indexes") {
db[colls[i]].createIndex( {"$**":"text"}, {name: "TextIndex"});
}
}
@josephmosby
josephmosby / mongo-django.py
Created March 25, 2015 15:03
Architecture for declaring a global MongoDB MongoClient in Django
#project/project/__init__.py
import project.settings
import pymongo
THE_MONGO_CLIENT = pymongo.MongoClient(settings.MONGO_HOST, settings.MONGO_PORT)
#project/project/settings.py
INSTALLED_APPS += 'utils'
MONGO_HOST = 'localhost' #default
@josephmosby
josephmosby / finding_variables.md
Last active August 29, 2015 14:20
Finding mysterious Django variables in templates

In a Django template file...

{% if last_updated %}Last Updated: {{ last_updated }}{% endif %}
{% endblock %}

Wait, where is last updated set?

$ grep -R "last_updated" .        	// where "." is the Django project directory

stuff
@josephmosby
josephmosby / format_date.js
Created April 28, 2015 15:14
JS Format an ISO8601 date as Django date string representation
var format_date = function(date) {
var month_names = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"];
js_date = new Date(date);
formatted_date = month_names[js_date.getMonth()] + ' ' + js_date.getDate() + ', ' + js_date.getFullYear()
+ ', ' + js_date.getUTCHours() + ':' + js_date.getUTCMinutes();
if(js_date.getHours() < 12) {
formatted_date += " a.m.";
} else {