Skip to content

Instantly share code, notes, and snippets.

View tifletcher's full-sized avatar

Themba Fletcher tifletcher

  • CrunchBase
  • San Francisco, CA
View GitHub Profile
@tifletcher
tifletcher / fix_jira.js
Last active June 20, 2017 08:14
Fix jira dashboards -- Remove extra sprints, re-sort, remove bogus height adjustments
(function () {
const $ = jQuery
const table_selector = ".issue-table"
const row_selector = ".issuerow"
const sprint_column_selector = ".customfield_10007"
function trim_sprint_column(i, column) {
const sprints = $(column).text().split(",")
const sprint = sprints[sprints.length - 1]
@tifletcher
tifletcher / PimpMyJsConsole-toHash.js
Created April 27, 2017 17:56
Convert an array of similar objects into an object with a common property as key
Array.prototype.toHash = function(key){
let hashMap = {}
this.forEach( (el) => {
hashMap[el[key]] = el
})
return hashMap
}
/*
> var arr = [{id: "a", thing: 123}, {id: "b", thing2: 456}]
@tifletcher
tifletcher / AvroTopicFactory.scala
Created February 25, 2017 00:03
avro topic / producer factory
package externalservices.kafka
import java.util.Properties
import application.utils.ConfigurationHelpers
import com.google.inject.{ImplementedBy, Inject, Singleton}
import com.sksamuel.avro4s.RecordFormat
import org.apache.avro.generic.GenericRecord
import org.apache.kafka.clients.producer.KafkaProducer
import play.api.Configuration
package com.dntty.util
object DependencyResolver {
/**
* Recursively resolve an element's dependencies into a flattened set of elements
*
* @param rootElement element whose dependencies will be resolved
* @param allElements set of elements from which dependencies will be extracted
* @param getId function which extracts an id of type K from an element of type T
import scala.collection.mutable
// largely cribbed from http://stackoverflow.com/q/16257378
object Memoize {
/**
* Simple memoizer backed by a mutable hashmap. Probably not thread safe.
* @param f function to be memoized
* @tparam K function parameter type
* @tparam V function return type
// toggle reading lense
(() => {
const distinct_id = "475eb1d6-04f6-4a6b-a550-4041b7ac9239";
const existing = document.getElementById(distinct_id);
if (existing) {
existing.parentNode.removeChild(existing);
} else {
document.body.appendChild(createLense(distinct_id, document));

Because sometimes faking it is enough.

@tifletcher
tifletcher / Higher-Kinded-Types-Example.scala
Last active May 4, 2016 06:09
Working out a bit of code duplication when working with Future[Option[T]], Future[Seq[T]], etc ... Stuff that you have to map into twice to transform.
package core.liststate
import java.util.UUID
import com.google.inject.Inject
import models.Tables
import services.ListStatesDataService
import scala.concurrent.Future
import scala.language.higherKinds
# disable mouse control by default - change 'off' to 'on' to enable by default.
setw -g mode-mouse on
set-option -g mouse-resize-pane on
set-option -g mouse-select-pane on
set-option -g mouse-select-window on
# toggle mouse mode to allow mouse copy/paste
# set mouse on with prefix m
bind m \
set -g mode-mouse on \;\
set -g mouse-resize-pane on \;\
final List<Future<UserProfile>> futures = userIds.stream().distinct().filter(Objects::nonNull)
.map(id -> new GetUserProfileCommand(registry, authToken, id, roleMap).queue())
.collect(Collectors.toList());
return futures.stream().parallel()
.map(f -> {
try {
return f.get();
} catch (InterruptedException | ExecutionException e) {
return null;