Skip to content

Instantly share code, notes, and snippets.

View deepak's full-sized avatar

Deepak Kannan deepak

View GitHub Profile
@deepak
deepak / pyg
Created March 20, 2014 02:05
script to create RTF for code snippets to paste in keynote presentations using pygments
#!/bin/bash
# /usr/local/bin/pygmentize -f rtf -O "style=friendly,fontface=Courier Bold" "$1" | pbcopy
# /usr/local/bin/pygmentize -l ruby -f rtf -P style=presentation -P fontface="Source Code Pro" "$1" | pbcopy
/usr/local/bin/pygmentize -l ruby -f rtf -O "style=friendly,fontface=Source Code Pro" "$1" |
# Set the font size to 36pt (that's the \fs72 - RTF font sizes work in doubles)
sed "s/\\\\f0/\\\\f0\\\\fs72/g" |
# And copy. Enjoy!
@deepak
deepak / dumb_metric_using_ruby_lint.rb
Last active August 29, 2015 13:57
A dumb metric which considers single variable names and floats as sins
require 'pp'
require 'pry'
require 'parser/current'
require 'ruby-lint'
require 'rake'
# @!attribute [r] vm
# @return [RubyLint::VirtualMachine]
class Analysis < RubyLint::Iterator
attr_reader :vm
@deepak
deepak / dump_metric.rb
Last active August 29, 2015 13:57
A dumb metric which considers single variable names and floats as sins. Uses parser and AST::Processor
require 'parser/current'
require 'pp'
require 'rake'
require 'pry'
module SexpLisper
def self.parse(path)
code = File.read(path)
source_buffer = Parser::Source::Buffer.new(path, 1)
@deepak
deepak / dumb_metric_treemap.rb
Created March 22, 2014 14:04
Visualize DumbMetric in active_support as a treemap
require 'parser/current'
require 'pp'
require 'rake'
require 'pry'
require 'treemap'
require 'treemap/image_output'
module SexpLisper
def self.parse(path)
code = File.read(path)
@deepak
deepak / dependency_analysis.rb
Last active August 29, 2015 13:57
analyse dependencies in a ruby file ie. constants
require 'parser/current'
require 'pp'
require 'pry'
require 'graph'
module SexpLisper
def self.parse(path)
code = File.read(path)
source_buffer = Parser::Source::Buffer.new(path, 1)
@deepak
deepak / rails engine Rakefile.rb
Last active August 29, 2015 13:57
Rakefile created for rails engine
# Rakefile generated with
# rails plugin new foo --mountable
begin
require 'bundler/setup'
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end
require 'rdoc/task'
@deepak
deepak / Disable pry for tests.rb
Created May 1, 2014 10:49
Disable pry for tests
# no pry in test environment but works otherwise
class Binding
def pry; nil; end
def remote_pry; nil; end
end
__END__
for finding a bug sometimes i will try it out in the browser
and set breakpoints in the code and javascript console
@deepak
deepak / lol_rspec.rb
Created May 2, 2014 07:47
lol_rspec.rb
RSpec.configure do |config|
config.around(:each) do |example|
# disabled by design
# example.call
end
end
__END__
if i have the above rspec config in `spec_helper.rb` and i run a test
@deepak
deepak / local variable shadows ivar.rb
Created May 15, 2014 09:51
local variable shadows ivar
class Foo
attr_accessor :params
def initialize(params)
@params = params
end
def process(params)
puts "====> before: #{params.inspect}"
params.merge!(local: "modifications")
@deepak
deepak / coffee-generated.js
Created January 30, 2015 13:24
ES6 classes
// Generated by CoffeeScript 1.7.1
(function() {
var Employee;
Employee = (function() {
function Employee() {}
Employee.prototype.doWork = function() {
return console.log("done");
};