Skip to content

Instantly share code, notes, and snippets.

View lkacenja's full-sized avatar

Leo Kacenjar lkacenja

  • Morris Animal Foundation
  • Denver, CO
View GitHub Profile
@lkacenja
lkacenja / gist:6887646
Created October 8, 2013 16:46
Adapted views-view-table template for Twig in Drupal 7. Approach would not be appropriate for D8 (or necessary).
<?php
// Preprocess
function minim_preprocess_views_view_table(&$variables) {
if (!empty($variables['header'])) {
$variables['headers_rendered'] = '';
foreach ($variables['header'] as $field => $label) {
$variables['headers_rendered'] .= "<th class='" . $variables['header_classes'][$field] . "'>" . $label . "</th>";
}
}
if (!empty($variables['rows'])) {
<?php
// Get All Airings BY Project Per Range
$start = 1383845472;
$end = 1384450272;
$query = db_select('field_data_field_om_airing_dates', 'dates');
$query->join('field_data_field_om_show_id', 'om_show', 'dates.entity_id=om_show.entity_id');
$query->join('field_data_field_om_show_project', 'project', 'om_show.field_om_show_id_value=project.entity_id');
$query->fields('project', array('field_om_show_project_nid'));
$query->addExpression('COUNT(field_om_show_project_nid)', 'airings');
$query->condition('dates.field_om_airing_dates_value', $start, '>=');
$start = 1383845472;
$end = 1384450272;
$query = db_select('field_data_field_om_airing_dates', 'dates');
$query->join('field_data_field_om_show_id', 'om_show', 'dates.entity_id=om_show.entity_id');
$query->join('field_data_field_om_show_project', 'project', 'om_show.field_om_show_id_value=project.entity_id');
$query->fields('project', array('field_om_show_project_nid'));
$query->fields('om_show', array('field_om_show_id_value'));
$query->fields('dates', array('field_om_airing_dates_value', 'field_om_airing_dates_value2'));
$query->condition('dates.field_om_airing_dates_value', $start, '>=');
$query->condition('dates.field_om_airing_dates_value2', $end, '<=');
@lkacenja
lkacenja / jquery.click-stopper.js
Created December 4, 2013 20:32
A simple script to prevent users from clicking a button or link many thousand times.
(function($) {
/**
* Jquery function to attach/detach click stopping.
* Call on link or input: $('selector').clickStopper({message: 'Optional message'});
* Destroy by calling again.
*/
$.fn.clickStopper = function(options) {
// return this to maintain chainability
return this.each(function() {
if ($(this).hasClass('click-stopper-processed')) {
@lkacenja
lkacenja / jquery.form-placeholder.js
Last active January 3, 2016 06:29
Simple tiny jQuery plugin to handle form placeholding super easily.
(function($) {
$.fn.placeholder = function(message) {
return this.each(
function() {
if ($(this).hasClass('form-placeholder-processed')) {
detach($(this));
}
else {
$(this).addClass('form-placeholder-processed');
$(this).data('form-placeholder', message);
<?php
function data_engine_node_view($node, $view_mode, $langcode) {
if ($node->type == 'indicator') {
$indicator_values = data_engine_indicator_values($node);
$dmetro_codes = data_engine_metro_denver_org_codes();
$dmetro_values = array();
foreach($indicator_values as $key => $info) {
if (array_key_exists($info->district_number, $dmetro_codes)) {
$dmetro_values[] = array(
'organization_name' => $dmetro_codes[$info->district_number],
<?php
function csi_api_indicator_get_data($nid) {
$values = array();
$all_data = &drupal_static(__FUNCTION__);
if (empty($all_data)) {
$all_data = array();
}
if (!empty($all_data[$nid])) {
return $all_data[$nid];
<!DOCTYPE html>
<html>
<head>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="./conway.js" ></script>
</head>
<body></body>
</html>
// conway.js
@lkacenja
lkacenja / google-distance-matrix.php
Created July 28, 2014 23:08
Class for using the google distance api
<?php
class omfGoogleDistanceMatrix {
protected $origins = array();
protected $destinations = array();
protected $unit = 'imperial';
protected $mode = 'driving';
protected $language = 'en';
protected $api_key = '';
protected $endpoint = 'https://maps.googleapis.com/maps/api/distancematrix/json';
@lkacenja
lkacenja / vincenty.php
Last active September 16, 2020 12:54
Vincenty Formula Jacked From Navigator PHP
// Inputs in Radians so degtorad degrees first.
function vincenty($lat1, $lon1, $lat2, $lon2) {
// Equitorial Radius
$a = 6378137.0;
// Polar Radius
$b = 6356752.31424518;
//Flattening of the ellipsoid
$f = 0.00335281066;
// Difference in longitude
$L = $lon2 - $lon1;