Skip to content

Instantly share code, notes, and snippets.

Stefan Kanev skanev

Block or report user

Report or block skanev

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View GRAPHQL.markdown

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 Mar 26, 2016
A patch for homebrew less to add a not very useful option
View less-quickshell.patch
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 Jan 29, 2015
Best. Math Joke. Ever.
View MATH_JOKE.markdown

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 Aug 29, 2015
My "slides" from WCEU 2014
View functional_programming.rb
# 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 Sep 19, 2019 — forked from valo/README.md
Hacky git diff syntax highlighting for the full code
View README.md

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 May 30, 2018
Syntax Highlight in Git Diff
View README.md

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 / rubocop.rb
Last active Oct 10, 2019
A Rubocop wrapper that checks only added/modified code
View rubocop.rb
#!/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 / counter_cache_test.rb
Last active Aug 29, 2015
An illustration of counter_cache and optimistic locking incompatiblity
View counter_cache_test.rb
require 'active_record'
require 'minitest/autorun'
require 'sqlite3'
require 'logger'
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection 'sqlite3::memory:'
ActiveRecord::Schema.define do
create_table :people do |t|
@skanev
skanev / generate.rb
Last active Jan 3, 2017
The peculiarities of Relation#distinct and Relation#count
View generate.rb
require 'active_record'
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Schema.define do
create_table :activities do |t|
t.string :day
t.string :name
end
end
View S06-contexts
#!/usr/bin/env zsh
c_dir=~/.zsh/contexts
c_contexts=($c_dir/*(:t))
c-chpwd() {
local matches
matches=(${${(s:/:)PWD}:*c_contexts})
if [[ $#matches -gt 1 ]]; then
You can’t perform that action at this time.