Skip to content

Instantly share code, notes, and snippets.

View bbarry's full-sized avatar

Bill Barry bbarry

  • Ren Inc
  • Pennsylvania
View GitHub Profile
@bbarry
bbarry / gist:710816
Created November 22, 2010 22:11
hits
import MetagenomeDB as mdb
names = ['check1', 'check2', 'check3']
def run():
c = mdb.Collection.find_one({"name": "NL10_1002_vRNA:contigs-strict"})
output=[]
for sequence in c.list_sequences():
if (not "alignments" in sequence):
continue
@bbarry
bbarry / gist:1885328
Created February 22, 2012 14:22
Dnn Additional Tab Settings module
public partial class PageSettings : System.Web.UI.UserControl {
protected override void OnPreRender(EventArgs e) {
base.OnPreRender(e);
if (Page.IsPostBack && PageUtil.IsPageValidated() && Page.IsValid &&
Page.Request.Params.Get(Page.postEventSourceID).Contains("cmdUpdate")) {
//cmdUpdate_click postback event occurred
var Tabs = new TabsController();
Tabs.UpdateTabSetting(TabId, "MyNewSetting", MySetting.Text);
}
@bbarry
bbarry / slidemessage.js
Created July 6, 2012 12:53
code review 13377
//http://codereview.stackexchange.com/questions/13377/jquery-drawer-with-tab
/*
preference: rename jquery instance variables to start with $
*/
$(function () {
var $message = $('#message'),
$tab = $('#tab'),
$droid = $message.find('.droid'),
speed = 300;
// Calendar
function calendar(d) {
$("#calendar").remove();
$("#calendar_container").append("<table border='1' id='calendar'></table>");
t = new Date(d); // Today [Wed Jan 16 2013 00:00:00 GMT-0500 (EST)]
var d = t.getDate(); // Today's date (1-31) [16]
var y = t.getFullYear(); // Full year [2013]
var m = t.getMonth(); // Month (0-11) [0]
@bbarry
bbarry / ai.js
Last active May 30, 2016 23:29
2048 - ai.js
var log2 = Math.log2;
if(!log2) {
log2 = function (x) { return Math.log(x) / Math.LN2; };
}
function Ai() {
var score = function (grid, previous) {
var total = 0, count = 0, ptotal = 0, pcount = 0;
grid.eachCell(function (x, y, tile) {
if (tile) { total += (log2(tile.value)-1)*tile.value; count += 1; }
/*
Implemented pseudocode available at
http://en.wikipedia.org/wiki/Mersenne_twister
as an asm.js module to learn about asm.js
*/
function MersenneTwister(stdlib, foreign, heap) {
"use asm";
@bbarry
bbarry / Cache.cs
Created February 27, 2015 19:45
Thread safe generic cache
public static class Cache<T> {
static readonly ConcurrentDictionary<string, T> Dictionary = new ConcurrentDictionary<string, T>();
//by making this a tuple with the generic constraint, there will be one per cache type; the first parameter will always be the default value
static readonly ConcurrentDictionary<string, Tuple<T, DateTime, TimeSpan>> Removals = new ConcurrentDictionary<string, Tuple<T, DateTime, TimeSpan>>();
/// <summary>
/// Gets an item out of the cache or adds it if it does not already exist.
/// </summary>
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace ConsoleApplication11 {
/*
output (cpu: i7 920)
Starting Benchmark
Running iteration: 1000/1000
Running 1000000 sub-iterations - Time Taken: 00:00:00.0043953
Running 1000000 sub-iterations - Time Taken: 00:00:00.0037585
Test 1
Average Time: 00:00:00.0043999
Invalid Operations: 750007614 (75.001 %)
@bbarry
bbarry / quicksort.cs
Created April 2, 2015 19:32
quicksort experiments
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;