Skip to content

Instantly share code, notes, and snippets.

@bdevel
bdevel / userscript.js
Created February 11, 2025 19:10
Stop trackpad zoom capture in Outlook web
// ==UserScript==
// @name Stop zoom capture in Outlook
// @namespace Violentmonkey Scripts
// @match https://outlook.office.com/*
// @grant none
// @version 1.0
// @author b
// @description 2/4/2025, 9:49:58 AM
// ==/UserScript==
@bdevel
bdevel / debouncer_flusher.rb
Last active January 20, 2025 20:42
A Ruby debounce utility that does not wait around and does not use threads.
# A debounce utility that does not wait around and does not use threads.
#
# Use DebounceFlusher.flush_on_finish{} to wrap any code
# that might call DebounceFlusher.run{}
# When the flush_on_finish block is complete, then any queued #run calls
# will be de-duplicated by the name provided to #run.
# The last call to #run for a specific name will be executed.
#
# NOTE, only one Thread will be able to execute this at a time due to the queue scope.
# Other threads will wait.
@bdevel
bdevel / text_helpers.clj
Last active November 22, 2024 00:35
Fast text searching of many, many sub-strings using Trie data structure
;; add [net.sourceforge.jregex/jregex "1.2_01"] as a dependency. Better Regex than Java.
(ns text-helpers
(:import [jregex Pattern Replacer Substitution MatchResult TextBuffer]))
(defn hexify
"debug helper for determine Unicode hex value for a char."
[s]
(apply str
@bdevel
bdevel / cache_util.clj
Created January 27, 2023 20:09
Clojure memoize function using a custom cache key
(ns example.cache-util
(:require [clojure.core.cache :refer [lru-cache-factory ttl-cache-factory]]
[clojure.core.cache.wrapped :refer [lookup-or-miss]]
))
(defmacro defn-lru-ttl-cached-by-key
"Defines function name, which will cache using the return value of key-fn which is passed args.
If cache miss, will run the value-forms which will have args in scope."
[name doc
max-qty ttl-ms
@bdevel
bdevel / web_service.clj
Last active November 3, 2022 18:16
Clojure Example running HTTPKit REST JSON service with logging and error handling
;; Example running HTTPKit REST JSON service
;; http://localhost:9843/api/example?q=12344
;; http://localhost:9843/
;; Add these to your project.clj
;; [ring "1.9.6"]
;; [ring/ring-defaults "0.3.4"]
;; [compojure "1.7.0"]
;; [http-kit "2.6.0"]
@bdevel
bdevel / 20160520223315_create_http_request_logs_table.rb
Last active May 26, 2016 18:36
Rails Database HTTP Logger - Rack Middleware
class CreateHttpLogsTable < ActiveRecord::Migration
def change
create_table :http_request_logs do |t|
t.datetime :created_at
t.string :request_method
t.text :path
t.jsonb :params
t.integer :http_status
t.integer :bytes_sent
t.integer :bytes_received
@bdevel
bdevel / adapter.js
Created May 12, 2016 23:46
Partially completed JSON API Ember Adapter and serializer for ElasticSearch.
import DS from 'ember-data';
import Ember from 'ember';
import ENV from 'my-app/config/environment';
Ember.ENV.DEBUG = true;
const {get} = Ember;
const ElasticSearchAdapter = DS.JSONAPIAdapter.extend({
@bdevel
bdevel / postgres_file_storage.rb
Last active July 28, 2016 22:03
Rails controller for storing and fetching files from Postgres Large Objects (LO)
require 'digest'
class Api::V2::FileStorageController < ApplicationController
skip_before_filter :authorize, :only => [:save, :serve]
before_filter :authorize_admin_api_token, :only => [:save]
def save
if params[:contents].is_a?(ActionDispatch::Http::UploadedFile)
params[:contents].close(false) # close and don't delete so we can import it
tmp_file = params[:contents]
@bdevel
bdevel / gist:a00b0146ff4610de7efc
Created June 9, 2015 01:02
Ember-pouch adapter with custom document IDs
import PouchDB from 'pouchdb';
import { Adapter } from 'ember-pouch';
var db = new PouchDB('app-database');
export default Adapter.extend({
db: db,
// Generates something like: 9f6kf-xz6by
// Much nicer than a full uuid