Skip to content

Instantly share code, notes, and snippets.

View michaelkoper's full-sized avatar

Michael Koper michaelkoper

  • Nusii
  • Madrid
View GitHub Profile
@michaelkoper
michaelkoper / apache_bench.sh
Last active June 2, 2016 08:50 — forked from seyhunak/apache_bench.sh
Rails - Apache Bench - Load Testing (if Warden Sign-in Required)
1.
LOGIN_PAGE=http://localhost.dev/users/sign_in
curl --cookie-jar cookie_file $LOGIN_PAGE | grep csrf-token
2.
<meta content="csrf-token" name="csrf-token" />
class CarrierStringIO < StringIO
def original_filename
# the real name does not matter
"photo.jpeg"
end
def content_type
"image/jpeg"
end
end
@michaelkoper
michaelkoper / backbone_pushstate_router.js
Last active October 5, 2016 21:28 — forked from tbranyen/backbone_pushstate_router.js
hijack links for pushState in Backbone. With open in new tab functionality.
// Use absolute URLs to navigate to anything not in your Router.
var openLinkInTab = false;
// Only need this for pushState enabled browsers
if (Backbone.history && Backbone.history._hasPushState) {
$(document).keydown(function(event) {
if (event.ctrlKey || event.keyCode === 91) {
openLinkInTab = true;
@michaelkoper
michaelkoper / gist:6668097
Last active December 23, 2015 17:19
Sublime User Keymap
[
{ "keys": ["ctrl+alt+super+d"], "command": "toggle_side_bar" },
{ "keys": ["super+shift+l"], "command": "expand_selection", "args": {"to": "line"} },
{ "keys": ["ctrl+super+r"], "command": "reveal_in_side_bar" },
{ "keys": ["super+shift+1"], "command": "focus_group", "args": { "group": 0 } },
{ "keys": ["super+shift+2"], "command": "focus_group", "args": { "group": 1 } },
{ "keys": ["alt+shift+up"], "command": "select_lines", "args": {"forward": false} },
{ "keys": ["alt+shift+down"], "command": "select_lines", "args": {"forward": true} },
{ "keys": ["command+shift+."], "command": "insert_snippet", "args": {"name": "Packages/User/erb.sublime-snippet"} },
{ "keys": ["ctrl+command+w"], "command": "run_macro_file", "args": {"file": "Packages/Default/Delete Line.sublime-macro"} },
@michaelkoper
michaelkoper / gist:6668089
Last active December 23, 2015 17:19
Sublime User Preferences
{
"auto_complete": false,
"auto_match_enabled": false,
"bold_folder_labels": true,
"color_scheme": "Packages/User/railscasts.tmTheme",
"folder_exclude_patterns":[
".svn",
".git",
".hg",
"CVS",
@michaelkoper
michaelkoper / gist:5007636
Last active January 25, 2018 18:25
Handling with money in Mongoid
class Product
include Mongoid::Document
field :price, type: Money
end
Money.class_eval do
# Converts an object of this instance into a database friendly value.
def mongoize
@michaelkoper
michaelkoper / gist:4772413
Last active December 12, 2015 12:29
Some handy media queries for mobile devices
@mixin mobile
@media (min-device-width: 320px) and (max-device-width: 568px)
@content
@mixin mobile-portrait
@media (min-device-width: 320px) and (max-device-width: 568px) and (orientation:portrait)
@content
@mixin mobile-landscape
@media (min-device-width: 320px) and (max-device-width: 568px) and (orientation:landscape)
@michaelkoper
michaelkoper / gist:1605401
Created January 13, 2012 10:12
No asset debug messages
# put in config/initializers/filename.rb
Rails.application.assets.logger = Logger.new('/dev/null')
Rails::Rack::Logger.class_eval do
def call_with_quiet_assets(env)
previous_level = Rails.logger.level
Rails.logger.level = Logger::ERROR if env['PATH_INFO'].index("/assets/") == 0
call_without_quiet_assets(env).tap do
Rails.logger.level = previous_level
end
@michaelkoper
michaelkoper / extra_memcached_features.rb
Created August 4, 2011 08:24
Extra features for memcache store Rails 2.1. Deleting a group of memcached keys.
module ActiveSupport
module Cache
class MemCacheStore
module Common
KEY = 'all_keys'
end
# Original method from the memcached store.
# Only difference is that we modify the key so we support Arrays