Skip to content

Instantly share code, notes, and snippets.

View skanev's full-sized avatar

Stefan Kanev skanev

View GitHub Profile
@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 / rubocop.rb
Last active February 12, 2025 02:36
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 / counter_cache_test.rb
Last active August 29, 2015 14:05
An illustration of counter_cache and optimistic locking incompatiblity
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 January 3, 2017 15:26
The peculiarities of Relation#distinct and Relation#count
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
#!/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
@skanev
skanev / Makefile
Last active August 29, 2015 14:01
Code from a live demo on the Python FMI course
gui:
python2 gui.py
cli:
python3 cli.py
test:
python3 tests.py
@skanev
skanev / constants.rb
Created January 15, 2014 09:06
Programming with Nothing Code lifted from book "Understanding Computation"
ZERO = -> p { -> x { x } }
ONE = -> p { -> x { p[x] } }
TWO = -> p { -> x { p[p[x]] } }
THREE = -> p { -> x { p[p[p[x]]] } }
FIVE = -> p { -> x { p[p[p[p[p[x]]]]] } }
FIFTEEN = -> p { -> x { p[p[p[p[p[p[p[p[p[p[
p[p[p[p[p[x]]]]]]]]]]]]]]] } }
HUNDRED = -> p { -> x { p[p[p[p[p[p[p[p[p[p[
p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[p[
@skanev
skanev / wtf.js
Created November 11, 2013 11:35
JavaScript!!1!
// Run it in chrome, just don't pass it to system()
(!![]+[])[+!+[]]+((+[])[([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]]+[])[+!+[]+[+!+[]]]+(+[![]]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+!+[]]]+(+((+(+!+[]+[+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+[!+[]+!+[]]+[+[]])+[])[+!+[]]+
@skanev
skanev / README.markdown
Created September 6, 2013 21:30
Call for collaboration

Personal Dashboard

I'm looking for someone to collaborate with on a (hopefully) small application.

Over the time I've found that I want to track various things that happen in my life in order to (1) improve productivity, (2) keep up to a schedule I picked or (3) just have an idea what is going on. For me this includes body weight, amount of exercise, time spent in various activities (coding, reading, watching TV), Pomodori completed and whatnot. This is reminiscent of the QuantifiedSelf movement.

The best way I see this is to have a "Personal Dashboard" where I can have all the numbers, charts and reminders I need. I envision it highly customizable – new things you want to keep track of pop up all the time and there should be a nice way to fit them in (like say, you started taking vitamins). Although there are a number of applications that can accomplish this (Lift, MyFitnessPal/FitDay, various Pomodoro timers, etc.), I want it simpler and I want it in one place. Furthermore, I enjoy customizing my habi