Skip to content

Instantly share code, notes, and snippets.

View skanev's full-sized avatar

Stefan Kanev skanev

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

@skanev
skanev / gist:5244311
Created March 26, 2013 10:08
Best Commit Ever
commit 79985f579cbe84722fde40a27271d513c2083d4a
Author: Stefan Kanev <stefan.kanev@gmail.com>
Date: Tue Mar 26 12:06:58 2013 +0200
Update current year
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 2cb2c01..e48b724 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
(ns lectures.parser-test
(:use clojure.test
lectures.parser)
(:require [clojure.string :as str]))
(defmacro expect
[parser & body]
`(are [input# output#] (= (parse ~parser input#) output#)
~@body))