Skip to content

Instantly share code, notes, and snippets.

View styx's full-sized avatar
🌴
¯\_(ツ)_/¯

Mikhail S. Pabalavets styx

🌴
¯\_(ツ)_/¯
View GitHub Profile
@german
german / active_record_introspection.rb
Created May 29, 2012 13:37
adding introspection to all ActiveRecord methods (putting method's name when it's invoked)
module ActiveRecord
Base.singleton_methods.each do |m|
Base.class_eval <<-EOS
class << self
puts "redefining #{m}"
define_method "#{m}_with_introspection" do |*args|
puts "#{m}"
send(:"#{m}_without_introspection", *args)
end
@prognostikos
prognostikos / app.js
Created September 11, 2012 13:45
AngularJS & Rails
/**
* Angular needs to send the Rails CSRF token with each post request.
*
* Here we get the token from the meta tags (make sure <%= csrf_meta_tags %>
* is present in your layout.)
*/
angular.module('myapp',[]).
// configure our http requests to include the Rails CSRF token
config(["$httpProvider", function(p) {
var m = document.getElementsByTagName('meta');
RSpec.configure do |c|
def profile
result = RubyProf.profile { yield }
name = example.metadata[:full_description].downcase.gsub(/[^a-z0-9_-]/, "-").gsub(/-+/, "-")
printer = RubyProf::CallTreePrinter.new(result)
open("tmp/performance/callgrind.#{name}.#{Time.now.to_i}.trace", "w") do |f|
printer.print(f)
end
end
@ethnt
ethnt / Gemfile
Last active December 15, 2015 14:49 — forked from passcod/Gemfile
How to use Sidekiq with Padrino.
# ...
gem 'sidekiq'
gem 'slim'
# ...
@avdi
avdi / gol.exs
Last active June 3, 2016 04:30
Game of life in Elixir (take 1)
defmodule Life do
def run(board) when is_binary(board) do
board |> parse_board |> run
end
def run(board) do
IO.write("\e[H\e[2J")
Life.print_board board
:timer.sleep 1000
board = next_board(board)
@styx
styx / kindle.sh
Created September 2, 2017 17:06 — forked from Madrigal/kindle.sh
Send files to your Amazon Kindle via the Command Line Interface.
# Command line utility to send attachments to your kindle
# It supports sending a PDF in both regular form and with the convert option
# and sending to the regular (@kindle.com) or free Kindle mail (@free.kindle.com)
# The only argument it has is the name of the file to send. It will detect if
# it is a pdf and treat it accordingly.
## Preferences
# If true, send one version with pdf as-is, another with 'convert' subject
# else, just send the pdf version
@nhance
nhance / method_logger.rb
Created September 6, 2012 12:58
Rails compatible method logging. Use this to log all calls to instance methods of a class to the log.
Model.new.foo
@Dr-Nikson
Dr-Nikson / README.md
Last active January 14, 2019 06:35 — forked from vjpr/README.md

Reduce boilerplate in Redux

  • Create actions similar to Flummox.
  • Generate action ids.
  • Supports actions with decorators, promises, and therefore ES7 async.
@davidalber
davidalber / python-cryptography-install.md
Created May 1, 2014 19:32
Steps to successfully install Python cryptography package on Mac OS X 10.8.5.

Prior to setting the PKG_CONFIG_PATH, as below, pip install cryptography failed with Symbol not found: _ffi_type_double on my machine running Mac OS X 10.8.5. I am not sure how commonly the error occurs for other users.

brew install libffi

# Note the version-specific path below.
PKG_CONFIG_PATH=/usr/local/Cellar/libffi/3.0.13/lib/pkgconfig/ pip install cryptography
mysql> EXPLAIN SELECT * FROM tf_users WHERE user_id = 'darkhelmet';
+----+-------------+----------+--------+---------------+------+---------+------+------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+----------+--------+---------------+------+---------+------+------+-------+
| 1 | SIMPLE | tf_users | system | NULL | NULL | NULL | NULL | 1 | |
+----+-------------+----------+--------+---------------+------+---------+------+------+-------+
1 row in set (0.00 sec)