Skip to content

Instantly share code, notes, and snippets.

@krosenberg
krosenberg / aqi.js
Last active October 12, 2020 21:39
Scriptable AQI widget
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: deep-green; icon-glyph: tree;
// change to the station id closest to you. station id can be found in the purple air url when you click on a sensor circle
// e.g. https://www.purpleair.com/map?opt=1/i/mAQI/a10/cC0&select=21057
const purpleAirStationID = 21057
let items = await loadItems()
let widget = await createWidget(items)
// Check if the script is running in
@krosenberg
krosenberg / VariablePageSizeCollection.js
Created December 2, 2015 17:16
A very rough concept for a collection that fetches pages of data with varying-length lists .
var RandomSize = Backbone.Collection.extend({
pageSize: 25,
nextPage: 1,
fullCollection: undefined,
url: '/forensics/api/random/',
parse: function(resp) {
return resp.data
},
getNextPage: function() {
var self = this;
@krosenberg
krosenberg / gist:fd8e9120de7a3479cb2a
Last active August 29, 2015 14:15
Perceived Date Statements
Choose the letter that best represents the time statement given in quotes.
If none of the answers are correct, answer 'none' or tell me what a better option would be.
If right now is Feb 19 10:14 AM...
1. "Last Hour"
A) Feb 19 9:00 AM - Feb 19 10:00 AM
B) Feb 19 9:14 AM - Feb 19 10:14 AM
2. "Past Hour"
@krosenberg
krosenberg / tagadder.js
Last active August 29, 2015 14:13
Wrap RegEx matches in a string with html tags (or anything)
var TagAdder = (function(regExp, openTag, closeTag) {
var regExp = regExp || /(?:)/gi;
var openTag = openTag || '<span class="highlighted">';
var closeTag = closeTag || '</span>';
function spliceSlice(str, index, count, add) {
return str.slice(0, index) + (add || "") + str.slice(index + count);
}
return {
@krosenberg
krosenberg / Backbone.ShowMoreCollection.js
Created September 4, 2014 18:05
A ShowMoreCollection for client-side-paginated Backbone.PageableCollection
/*
showMore() Adds more models to the first page of a pageable collection.
It does this by resetting the collection to the current collection plus a number of models
from fullCollection, and increases the page size to the number of currently-visible models.
*/
Backbone.ShowMoreCollection = Backbone.PageableCollection.extend({
showMore: function(num) {
var num = num || 10;
var state = this.state;
var pageNum = state.currentPage;
@krosenberg
krosenberg / README.md
Last active February 19, 2023 19:41
D3 "force" layout with nodes situated around a circle

####D3 "force" layout with nodes situated around a circle

This network graph uses the D3 force layout to draw nodes and links, but instead of using d3.force() to find the best node positions, we draw an invisible arc and evenly places nodes along the circumference.

initialize: function() {
this.submit = _.debounce(this.submit, 300);
},
filterOnKeyUp: function(e) {
this.submit();
},
@krosenberg
krosenberg / custom backgrid
Created February 26, 2014 23:22
custom backgrid search filters
1) include <script src="{{STATIC_URL}}v2/js/backgrid-custom.js" type="text/javascript"></script> after the final backgrid js file.
2) use the following to render a filter:
var processGroupFilter = new simpleFilter({
collection: this.collection,
placeholder: "Search Process Groups",
fields: ["name", "template", "target"];
});
@krosenberg
krosenberg / Markup for market items.html
Created February 25, 2014 18:27
Markup for market items
<ul class="list-unstyled">
<li class="market-item">
<div class="market-item-image">
<div class="market-item-circle circle-image">
<img src="filename_of_image" width="40" height="40"/>
</div>
</div>
<h4 class="market-item-title primary-color">
@krosenberg
krosenberg / README.md
Last active January 2, 2016 04:09
Minimal Charts

These work well when a small graph is needed in a small space. Includes minimal mouseover interaction.