Skip to content

Instantly share code, notes, and snippets.

View camd's full-sized avatar

Cameron Dawson camd

View GitHub Profile
import React from 'react';
export const PinBoardContext = React.createContext({
pinnedJobs: [],
relatedBugs: [],
pinJob: () => { console.log("pinJob raw"); },
addBug: () => { console.log("addBug raw"); },
});
export function withPinBoard(Component) {
@camd
camd / highlightHelper.jsx
Created April 12, 2018 18:51
highlightCommonTerms jsx
// Remove disabling when there is more than one export in the file.
// eslint-disable-next-line import/prefer-default-export
export const highlightCommonTerms2 = function highlightCommonTerms2(text, terms) {
const termTokens = terms.split(/[^a-zA-Z0-9_-]+/);
const textTokens = text.split(" ");
// can we do an "includes" that works on substrings? Otherwise write your own checker
return (
<span>
{textTokens.map((textElem, idx) => (
termTokens.some(arrElem => (textElem.replace(/\W/g, '') === arrElem)) ?
treeherder.filter('highlightCommonTerms2', function () {
return function (input) {
const compareStr = Array.prototype.slice.call(arguments, 1).filter(x => x).join(" ");
let tokens = compareStr.split(/[^a-zA-Z0-9]+/).map(item => item.toLowerCase());
tokens = [ ...new Set(tokens) ]; // remove duplicates
console.log("tokens", tokens);
const subs = tokens.reduce((subAcc, token) => {
let innerSubs = tokens.filter(innerToken => (innerToken.includes(token)));
let substr = innerSubs.filter(sub => sub !== token);
return [ ...subAcc, ...substr ];
@camd
camd / helper.py
Created July 20, 2017 22:15
graphene_django select_related
from graphene_django.filter import DjangoFilterConnectionField
from graphql.utils.ast_to_dict import ast_to_dict
def collect_fields(node):
non_fields = ["edges", "node"]
fields = []
for leaf in node:
if leaf.get('kind', None) == "Field" and not leaf["name"]["value"] in non_fields:
fields.append(leaf["name"]["value"])
@camd
camd / reactselect.jsx
Created September 9, 2016 22:07
React Select component with spinner for long lists
'use strict';
/*
This ended up being fast enough to not need the spinner. and it may
have even slowed it down a bit, not clear. But this might be handy some day.
*/
var ReactSelectComponent = React.createClass({
displayName: 'ReactSelectComponent',
propTypes: {
list: React.PropTypes.array.isRequired,
import json
from thclient import (TreeherderClient,
TreeherderJobCollection)
job = {
"job_guid": "1a1f13c7-f14d-48c6-8d6b-cb08501ef42c/1",
"build_system_type": "taskcluster",
"build_platform": {
"platform": "b2g-emu-jb",
$rootScope.$on(thEvents.selectNextJob, function(ev){
var jobMap = ThResultSetModel.getJobMap($rootScope.repoName);
var el, key, job;
var jobs = $(".th-view-content .job-btn");
var idx = jobs.index(jobs.filter(".selected-job"));
idx = idx+1 > _.size(jobs)? 0: idx+1;
el = $(jobs[idx]);
while (el.css('display') === "none") {
[cdawson@treeherder-processor1.stage.private.scl3 ~]$ mysql -h treeherder-stage-ro-vip.db.scl3.mozilla.com -u th_user -p
Enter password:
ERROR 2003 (HY000): Can't connect to MySQL server on 'treeherder-stage-ro-vip.db.scl3.mozilla.com' (110)
@camd
camd / gist:81582c99ca38eaecf02c
Created October 14, 2014 21:29
treeherder service vagrant bash cheats
function super {
sudo supervisord -c deployment/supervisord/$1_node.conf
}
cd ~/treeherder-service
export PS1='\[\e[0;31m\]\u\[\e[m\] \[\e[1;34m\]\w\[\e[m\] \$ '
@camd
camd / gist:f9c4f9c975f4e8e29588
Created September 23, 2014 21:24
defer for treestatus
var updateAllWatchedRepoTreeStatus = function() {
$log.debug("updateAllWatchedRepoTreeStatus", repos);
_.each(_.keys(repos), function(repo) {
_.defer(updateTreeStatus, repo);
});
};