Skip to content

Instantly share code, notes, and snippets.

View emptyflask's full-sized avatar

Jon Roberts emptyflask

View GitHub Profile
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
ruby-nix.url = "github:inscapist/ruby-nix";
bundix = {
url = "github:inscapist/bundix/main";
inputs.nixpkgs.follows = "nixpkgs";
};
fu.url = "github:numtide/flake-utils";
bob-ruby.url = "github:bobvanderlinden/nixpkgs-ruby";
@emptyflask
emptyflask / boolean.rb
Created November 16, 2021 20:25
ruby `#to_boolean` extension
require 'bigdecimal'
module CoreExtensions
module String
def to_boolean
!!(self =~ /^(true|t|yes|y|1)$/i)
end
end
module Integer
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
require 'bundler/setup'
require 'active_model'
require 'active_support/concern'
require 'virtus'
module EventParams
include Virtus.module
extend ActiveSupport::Concern
include ActiveModel::Validations
@emptyflask
emptyflask / 20180207210749_convert_film_ids_to_strings.rb
Created October 5, 2021 17:58
DB view migration wrapper using Scenic
require 'migration/rebuild'
class ConvertFilmIdsToStrings < ActiveRecord::Migration[5.1]
include Migration::Rebuild
EVENT_VIEWS = {
# view: version
eventbase_events: 26,
eventbase_entities: 34,
admin_entity_stats: 8,
@emptyflask
emptyflask / bench.rb
Last active January 31, 2022 16:23
Benchmark questionable code!
require 'benchmark/ips'
require 'benchmark/memory'
# IPS = iterations per second
# https://github.com/evanphx/benchmark-ips
string = "123"
%i[ips memory].each do |bench|
puts bench.upcase
@emptyflask
emptyflask / structish.md
Last active September 7, 2021 17:54
Struct/OpenStruct/Hash

Struct for throwaway objects, OpenStruct only when keys may change, or you have a hash and must have accessor methods.

# Fastest, needs to initialize a Struct first
T = Struct.new(:name)
t1 = T.new('test')
t1.name # => 'test'
t1.foo # => error!

# Fast, needs to use hash lookups
@emptyflask
emptyflask / default.nix
Created May 19, 2021 19:01
Generate load icons for Xmobar (with nix support)
{ nixpkgs ? import <nixpkgs> {} }:
with nixpkgs;
let
ImageBase = perlPackages.buildPerlPackage {
pname = "Image-Base";
version = "1.17";
src = fetchurl {
@emptyflask
emptyflask / hoogle.nix
Created December 18, 2020 04:06
Hoogle instance on NixOS
{pkgs, lib, system, ...}:
let
notBroken = (p: lib.isDerivation p && !(p.meta.broken or false));
in
{
services.hoogle = {
enable = true;
port = 8081;
import Data.Monoid
import Data.Foldable
data Tree a = Empty
| Node (Maybe a)
(Tree a)
(Tree a)
deriving (Show)
instance Foldable Tree where