Skip to content

Instantly share code, notes, and snippets.

View skanev's full-sized avatar

Stefan Kanev skanev

View GitHub Profile
@skanev
skanev / Apollo+Rx.swift
Last active April 30, 2024 15:07
Homegrown fetchMore in Apollo iOS
import Foundation
import RxSwift
import RxRelay
import Apollo
// MARK: - Apollo Support
enum ApolloError: Error {
case genericError(String)
case graphqlErrors([GraphQLError])
@skanev
skanev / rubocop.rb
Last active March 13, 2024 08:24
A Rubocop wrapper that checks only added/modified code
#!/usr/bin/env ruby
# A sneaky wrapper around Rubocop that allows you to run it only against
# the recent changes, as opposed to the whole project. It lets you
# enforce the style guide for new/modified code only, as opposed to
# having to restyle everything or adding cops incrementally. It relies
# on git to figure out which files to check.
#
# Here are some options you can pass in addition to the ones in rubocop:
#
@skanev
skanev / 00-ADVENT-OF-CODE-2022-RUBY.md
Last active February 21, 2024 13:07
Advent of Code 2022 in Ruby (sort of)

Advent of Code 2022 solutions in Perl Ruby

Just for kicks, I'm trying to solve them with semi-golfed Ruby. That is:

  • As short as possible, but
  • Have some whitespace to make them somewhat readable
  • Avoid single-letter identifiers to keep them somewhat readable
  • Don't make them too short when they are short enough

Each solution parses the input file and outputs the answer.

@skanev
skanev / dev-bg.ts
Created June 21, 2023 17:39
Dev BG example code
console.log('baba')
// 1. Literal types
{
let meta: 'foo' = 'foo'
meta = 'foo'
// @ts-expect-error
meta = 'bar'
@skanev
skanev / README.md
Last active October 26, 2023 12:02 — forked from valo/README.md
Hacky git diff syntax highlighting for the full code

Hacky syntax highlighting in git diff

Normally git diff would color additions green and deletions red. This is cool, but it would be even cooler if it adds syntax highlighting to those lines. This is a git pager that does so.

It parses the diff output and picks up the SHAs of files with additions and deletions. It uses [CodeRay][coderay] to highlight each file and then it extracts the lines that are shown in the diff. It then uses [term/ansicolor][color] to make a gradient from the CodeRay color and the diff color (red for deletion, green for addition) and uses it to replace the original.

I tried using rugged instead of shelling out to git show – it was faster overall, but it did incur a noticeable start up time.

Check out the image below for a demo.

@skanev
skanev / README.md
Last active January 12, 2023 19:13
Syntax Highlight in Git Diff

Hacky syntax highlighting in git diff

Normally git diff would color additions green and deletions red. This is cool, but it would be even cooler if it adds syntax highlighting to those lines. This is a git pager that does so.

It parses the diff output and picks up the SHAs of files with additions and deletions. It uses [CodeRay][coderay] to highlight each file and then it extracts the lines that are shown in the diff. It then uses [term/ansicolor][color] to make a gradient from the CodeRay color and the diff color (red for deletion, green for addition) and uses it to replace the original.

I tried using rugged instead of shelling out to git show – it was faster overall, but it did incur a noticeable start up time.

Check out the image below for a demo.

@skanev
skanev / autocomplete_from_tmux.sh
Created February 1, 2012 09:41
zsh: autocomplete words in current tmux session
# Autocomplete from current tmux screen buffer
_tmux_pane_words() {
local expl
local -a w
if [[ -z "$TMUX_PANE" ]]; then
_message "not running inside tmux!"
return 1
fi
w=( ${(u)=$(tmux capture-pane \; show-buffer \; delete-buffer)} )
_wanted values expl 'words from current tmux pane' compadd -a w
#!/usr/bin/env zsh
typeset -gA jump_locations
jump_locations=(
zeitwerk ~/prj/zeitwerk
rails ~/prj/rails-dev-box/rails
tmp ~/tmp
)
@skanev
skanev / close_hidden_buffers.vim
Created July 6, 2011 20:15
Close all hidden buffers in Vim
command! CloseHiddenBuffers call s:CloseHiddenBuffers()
function! s:CloseHiddenBuffers()
let open_buffers = []
for i in range(tabpagenr('$'))
call extend(open_buffers, tabpagebuflist(i + 1))
endfor
for num in range(1, bufnr("$") + 1)
if buflisted(num) && index(open_buffers, num) == -1
@skanev
skanev / generic_operations.py
Created November 8, 2012 08:48
Data-Directed Programming Example Code
operations = {}
def get(name, types):
return operations.get((name,) + types)
def put(name, args, code):
operations[(name,) + args] = code
def apply_generic(name, *args):
types = tuple(map(type, args))