Skip to content

Instantly share code, notes, and snippets.

View lkacenja's full-sized avatar

Leo Kacenjar lkacenja

  • Code for America
  • Denver, CO
View GitHub Profile
@lkacenja
lkacenja / years.php
Created January 2, 2017 17:47
Years to taxonomy
<?php
use Drupal\taxonomy\Entity\Term;
$min = 2001;
$max = 2016;
for ($i = $min; $i <= $max; $i ++) {
$term = Term::create([
'name' => $i ,
'vid' => 'year',
import assign from 'object-assign';
import actionTypes from '../utility/action-types';
export default function = function(settings) {
const defaultState = {
config: settings.filters,
values: {}
};
@lkacenja
lkacenja / counties-to-vocabulary.php
Last active November 18, 2016 21:04
Load Colorado Taxonomy Terms Into a Drupal 8 Vocabulary
<?php
use Drupal\taxonomy\Entity\Term;
function county_alphabetize($a, $b) {
return $a->properties->NAMELSAD > $b->properties->NAMELSAD;
}
$county = file_get_contents('https://raw.githubusercontent.com/kthotav/TopoJSON-Maps/master/usa/usa-states/colorado/colorado-counties.json');
$json = json_decode($county);
<?php
$route_name = \Drupal::routeMatch()->getRouteName();
$bits = explode('.', $route_name);
for ($i = 0; $i < count($bits); $i ++) {
if ($i == 0) {
$body_classes[] = str_replace('_', '-', $bits[$i]);
}
else {
$body_classes[] = str_replace('_', '-', $bits[$i - 1] . '-' . $bits[$i]);
@lkacenja
lkacenja / kmeans.php
Last active October 20, 2016 19:48
Exact port Simple Script's ckmeans algorithm (https://github.com/simple-statistics/simple-statistics) to PHP. Useful for creating choropleth breaks and such.
<?php
function makeMatrix($columns, $rows) {
$matrix = array();
for ($i = 0; $i < $columns; $i ++) {
$column = array();
for ($j = 0; $j < $rows; $j ++) {
$column[] = 0;
}
$matrix[] = $column;
if (!isset($_SERVER['HTTPS']) || strpos($_SERVER['HTTP_HOST'], 'www') === FALSE) {
header('HTTP/1.0 301 Moved Permanently');
header('Location: https://www.creatingtransitions.org'. $_SERVER['REQUEST_URI']);
exit();
}
var _this = this;
chrome.cast(
function(data) {
_this.success.call(_this, data);
},
function(error) {
_this.error.call(_this, error);
}
);
@lkacenja
lkacenja / webpack-config.js
Last active February 10, 2016 17:32
Webpack config for using global node modules on mac os 10.9
// Don't forget export NODE_PATH=/usr/lib/node_modules:$NODE_PATH
var path = require("path");
var pathToModules = path.resolve("/usr/local/lib/node_modules");
module.exports = {
resolve: {
fallback: pathToModules
},
resolveLoader: {
fallback: pathToModules
},
function parseBool(b) {
if (!!(b)) {
return b;
}
if (b == 'true') {
return true;
}
if (b == 'false' || b == 0 || b == null || b == undefined) {
return false;
}
@lkacenja
lkacenja / package.json
Last active December 16, 2015 20:09
package.json for webpack + babel
{
"name": "OMF-React-Stack",
"version": "0.0.0",
"description": "",
"main": "setup.js",
"dependencies": {
"babel-core": "^6.3.17",
"babel-loader": "^6.2.0",
"babel-plugin-transform-react-jsx": "^6.3.13",
"babel-preset-es2015": "^6.3.13",