Skip to content

Instantly share code, notes, and snippets.

View bradoyler's full-sized avatar
👋
say hi

brad oyler bradoyler

👋
say hi
View GitHub Profile
@bradoyler
bradoyler / DataContextWrapper.cs
Created November 2, 2012 13:01
A DataContext wrapper for LINQ to SQL model.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Common;
using System.Data.Linq;
namespace MyApp.Models.DataContextWrapper
{
public interface IDataContextWrapper
@bradoyler
bradoyler / .block
Last active April 29, 2023 19:28
US Flight animation (svg)
license: mit
import NodeCache from 'node-cache'; // or 'redis'
class CacheService {
constructor(ttlSeconds) {
// this could also be redis
this.cache = new NodeCache({ stdTTL: ttlSeconds, checkperiod: ttlSeconds * 0.2, useClones: false });
}
get(key, storeFunction) {
@bradoyler
bradoyler / mapReduce-WordCounter.js
Last active November 6, 2022 01:45
Using Map-Reduce in Javascript: counting words in a string.
// for counting words in a string
var words="Hi there and hello there. Welcome and hello there.";
var wordcnt = words.replace(/[^\w\s]/g, "").split(/\s+/).reduce(function(map, word){
map[word] = (map[word]||0)+1;
return map;
}, Object.create(null));
@bradoyler
bradoyler / sleepSort.js
Last active June 6, 2022 17:36
sorting algorithm using setTimeout
function sleepSort(arr) {
arr.forEach((n) => setTimeout(() => console.log(n), n))
}
const arr = [9, 5, 3, 99, 11, 2, 0]
sleepSort(arr)
/* stdout:
0
2
@bradoyler
bradoyler / inheritance.js
Last active February 26, 2022 09:53
JS inheritance. Explained.
// via http://www.klauskomenda.com/code/javascript-inheritance-by-example/
// create constructor function for base "class"
function Vehicle(hasEngine, hasWheels) {
this.hasEngine = hasEngine || false;
this.hasWheels = hasWheels || false;
}
// create constructor function
function Car (make, model, hp) {
this.hp = hp;
// jquerify.js // https://github.com/bgrins/devtools-snippets // Add jQuery to any page that does not have it already.
(function() {
if (!window.jQuery) {
var s = document.createElement('script');
s.setAttribute('src', '//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js');
document.body.appendChild(s);
console.log('jquery loaded!');
@bradoyler
bradoyler / .block
Last active November 28, 2021 14:33
Crude Oil Pipelines in US
license: mit
@bradoyler
bradoyler / 24.md
Last active June 16, 2021 20:50
The 24 game in javascript

The 24 Game

  • tests one's mental arithmetic.

How it works:

  • You are randomly given four digits, each from one to nine, with repetitions allowed.
  • The goal is to enter an expression that evaluates to 24
Tips:
  • Only multiplication, division, addition, and subtraction operators/functions are allowed.
  • Division should use floating point or rational arithmetic, etc, to preserve remainders.
@bradoyler
bradoyler / .block
Last active June 29, 2020 14:39
crime rates in US cities
license: mit