Skip to content

Instantly share code, notes, and snippets.

@mish15
mish15 / channel-processing-queue.go
Last active April 24, 2019 19:07
No blocking channel based queue processor example
package main
import (
"fmt"
"time"
)
func main() {
queue := make(chan int, 5) // buffer up to 5 items to be processed
done := make(chan bool)
@mish15
mish15 / install.html
Last active October 9, 2018 17:26
hfma.org install
<h3>Search Box in your nav</h3>
<p>Once installed on your site, searching from this search box will take you to your search page at /GSASearch.aspx.</p>
<!-- 1. Add to global navigation to create a global search box -->
<div id="nav-search-box"></div>
<!-- 1. Add to global navigation to create a global search box -->
<hr>
@mish15
mish15 / install.html
Last active October 4, 2018 18:27
TribLive priority install
<h3>Nav autosuggest box</h3>
<div id="nav-search-box"></div>
<hr>
<h3>Results Page</h3>
<div id="results-search-box"></div>
<div id="results-search-response"></div>
@mish15
mish15 / install.js
Last active September 15, 2018 00:34
MNYS install
// Step 1: global search box
// Put into main template (all pages)
// Assumes ID of search box will remain unchanged: CT_Header_0_ctl01_txtSearch
var getUrlParam = function(e){var t = new RegExp("[?&]" + e.replace(/[\[\]]/g, "\\$&") + "(=([^&#]*)|&|#|$)"),a = t.exec(window.location.href);return a && a[2] ? decodeURIComponent(a[2].replace(/\+/g, " ")) : ""};
var setup = function(w,d,x,a,e,s,c,r){s = [];var b=function(){s.push(arguments);},q="ui";b.arr=s;w[a]=w[a]||[];w[a][q]=w[a][q]||[];w[a][q].push(b);c=d.createElement(x);c.async=1;c.src=e;r=d.getElementsByTagName(x)[0];r.parentNode.insertBefore(c,r);return b;};
var searchBox = setup(window, document, "script", "sajari", "//cdn.sajari.net/js/integrations/website-search-1.4.js");
searchBox({
mode: "search-box",
project: "1520368576952702052", // Set this to your project.
@mish15
mish15 / install.js
Last active September 8, 2018 03:20
Dynamic content block
// 1. Assumes the following div exists in the page, note: you can change this using the "attachDynamicContent" setting
// <div id="dynamic-content"></div>
// 2. The "pipeline" parameter controls the query execution, this example uses "popular", this is configurable
// 3. The "values" map controls the query. You don't need the "q" parameter, but can use this to control the context of
// the results. For example you may wish to use the "document.title" to find related content to the current page
// 4. The filter parameter allows any number of filters to be used to filter the query results, e.g. to domains, or sections,
// or any other number of factors
var recommend = setup(window, document, "script", "sajari", "//cdn.sajari.net/js/integrations/website-search-1.4.js");
recommend({
@mish15
mish15 / flatbuffers-vector.go
Created June 23, 2015 00:18
flatbuffers pack nested vector
func (term *Term) Encode(version string) []byte {
builder := flatbuffers.NewBuilder(0)
// Preprocess the shotguns
shotguns := make([]flatbuffers.UOffsetT, len(term.Shotgun))
shotgunStrs := make([]flatbuffers.UOffsetT, len(term.Shotgun))
for i := 0; i < len(term.Shotgun); i++ {
shotgunStrs[i] = builder.CreateString(term.Shotgun[i].Term)
}
for i := 0; i < len(term.Shotgun); i++ {
@mish15
mish15 / rev indexes using cgo
Created March 28, 2014 00:36
Using cgo to take memory off heap
package main
/*
#cgo CFLAGS: -O3
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#define SJ_REV_BUCKET_SIZE 10000 // The maximum number of terms that the bucket can hold