Skip to content

Instantly share code, notes, and snippets.

View skanev's full-sized avatar

Stefan Kanev skanev

View GitHub Profile
@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 / 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.

#!/usr/bin/env zsh
typeset -gA jump_locations
jump_locations=(
zeitwerk ~/prj/zeitwerk
rails ~/prj/rails-dev-box/rails
tmp ~/tmp
)
@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 / GRAPHQL.markdown
Last active April 27, 2017 19:38
On GraphQL

I like GraphQL for the regular reasons. It feels to me that it delivers on its promise, althought it's not simple or straightforward to start using it (but neither is SQL itself).

I'll approach this from two perspectives:

Using a GraphQL API as a client

I had the experience on this side when doing a small internal app ontop of the GitHub GraphQL API. The previous version was using the REST API and it had a

@skanev
skanev / less-quickshell.patch
Last active March 26, 2016 14:40
A patch for homebrew less to add a not very useful option
diff --git a/command.c b/command.c
index c31fa81..11d7483 100644
--- a/command.c
+++ b/command.c
@@ -273,10 +273,13 @@ exec_mca()
if (secure)
break;
- if (shellcmd == NULL)
+ if (shellcmd == NULL) {
@skanev
skanev / MATH_JOKE.markdown
Created January 29, 2015 14:08
Best. Math Joke. Ever.

When the Ark eventually lands after the Flood, Noah releases all the animals and makes a proclamation: "Go forth and multiply".

Several months later, Noah is delighted to see that all the creatures are breeding, except a pair of snakes, who remain childless. Noah asks: "What's the problem?" The snakes have a simple request of Noah: "Please cut down some trees and let us live there."

Noah obliges, leaves them alone for a few weeks and then returns. Sure enough, there are lot of baby snakes. Noah asks why it was important to cut down the trees, and the snakes reply: "We're adders, and we need logs to multiply."

@skanev
skanev / functional_programming.rb
Last active August 29, 2015 14:14
My "slides" from WCEU 2014
# encoding: utf-8
def annotate(string, code = '4')
string.gsub(/@(.*?)@/, "\e[#{code}m\\1\e[0m")
end
def colorize(string)
string.gsub(/#(.*?)#/, "\e[\\1m").gsub(/##/, "\e[0m")
end
@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.