Skip to content

Instantly share code, notes, and snippets.

View shirts's full-sized avatar

shirts shirts

  • probably somewhere
View GitHub Profile
@shirts
shirts / csharp.vim
Created December 22, 2023 23:07
C# Dotnet show virtual text warnings/errors in vim virtual text
" Call DotnetRunAndShowVirtualText on file open & save
autocmd BufReadPost,BufWritePost *.cs | call DotnetRunAndShowVirtualText()
" Delete virtual text on a buffer when it is modified
autocmd TextChanged,TextChangedI *.cs lua vim.api.nvim_buf_clear_namespace(0, -1, vim.fn.line(".") - 1, vim.fn.line("."))
highlight MyWarningVirtualText guifg=orange
highlight MyErrorVirtualText guifg=red
function! DotnetRunAndShowVirtualText()
lua << EOF
@shirts
shirts / main.rs
Created October 22, 2023 04:52
Rust transpose
pub fn transpose(matrix: [[i32; 3]; 3]) -> [[i32; 3]; 3] {
let mut transposed: [[i32; 3]; 3] = [[0; 3]; 3];
for i in 0..matrix.len() {
for j in 0..matrix[i].len() {
transposed[i][j] = matrix[j][i];
}
}
transposed
@shirts
shirts / README.md
Last active January 24, 2020 16:39
Sequel Playground

ruby migrate.rb create ruby migrate.rb drop

$ irb

require_relative 'sequel'

user = User.first

user.send_welcome_email

@shirts
shirts / lucky_numbers.rb
Last active November 27, 2019 18:15
Lucky Numbers
class LuckyNumbers
attr_accessor :lucky_number
LUCKY_NUMBER = 7
INTERVAL = 9
def initialize(min = 0)
@lucky_number = min.to_i - 1
end
def lucky?(number)
@shirts
shirts / colors_enum.rb
Created October 12, 2019 00:55
Ruby Enumerable example
class ColorsEnum
include Enumerable
def initialize(colors)
@colors = colors
end
def each(&block)
block.call(@colors[0])
@colors.shift
@shirts
shirts / basic_erb.rb
Created October 10, 2019 21:31
ERB binding
require 'erb'
class BasicErb
def initialize(template)
@template = template
end
def greeting
"Hello World!"
end
@shirts
shirts / abstract_interface.rb
Last active October 7, 2019 18:15
Abstract Interface
module AbstractInterface
class InterfaceNotImplementedError < NoMethodError
end
def self.included(base)
base.send(:include, AbstractInterface::Methods)
base.send(:extend, AbstractInterface::Methods)
base.send(:extend, AbstractInterface::ClassMethods)
end
O(1) = Immediately know exactly which element to visit (array by index, hash table lookup)
O(n) = Visit element once (find something in a list of unique values)
O(log n) = Loop the whole list multiple times but reduce its size each iteration roughly by half (sorting algorithms like quick sort [or is it merge sort]?)
O(n^2) = Loop the whole list for each element in the list (nested loops) (edited)
@shirts
shirts / cherry_picked_active_support.rb
Last active May 10, 2017 04:49
Active Support Helpers
# "In order to have a near-zero default footprint, Active Support does not
# load anything by default. It is broken in small pieces so that you can
# load just what you need, and also has some convenience entry points to
# load related extensions in one shot, even everything."
require 'active_support'
# https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/object/blank.rb
require 'active_support/core_ext/object/blank'
# https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/object/inclusion.rb
@shirts
shirts / Terminology.md
Created March 1, 2017 00:32
Terminology

Concerns: modules that you mixin to the classes where they are needed