Skip to content

Instantly share code, notes, and snippets.

View dmitry's full-sized avatar
🇪🇪
Water, earth and air.

Dmitry Polushkin dmitry

🇪🇪
Water, earth and air.
View GitHub Profile
@mildmojo
mildmojo / left_join_arel_example.rb
Last active April 5, 2024 16:00
LEFT JOIN in ARel for ActiveRecord in Ruby on Rails
# Here's a contrived example of a LEFT JOIN using ARel. This is an example of
# the mechanics, not a real-world use case.
# NOTE: In the gist comments, @ozydingo linked their general-purpose ActiveRecord
# extension that works for any named association. That's what I really wanted!
# Go use that! Go: https://gist.github.com/ozydingo/70de96ad57ab69003446
# == DEFINITIONS
# - A Taxi is a car for hire. A taxi has_many :passengers.
# - A Passenger records one person riding in one taxi one time. It belongs_to :taxi.
@andflett
andflett / sir-trevor-active-admin.css
Created October 4, 2012 12:36
Make Sir Trevor more presentable in ActiveAdmin
body {
margin: 0;
line-height: 150%;
font-size: 72%;
}
form .sir-trevor {
width: 860px;
margin: 30px auto;
background: #ffffff;
$VERBOSE = nil
require File.expand_path('../rooby', __FILE__)
Person = Rooby::Class.new 'Person' do
define :initialize do |name|
@name = name
end
define :name do
@polimorfico
polimorfico / gist:4074902
Created November 14, 2012 21:18
Force your params encoding in Rails

If you have problems with your params encodings, use a Rack middleware to encode them before rails params parsing code is executed.

First, build a class according to the signature of a rack middleware layer.

#lib/force_params_encoding.rb
class ForceParamsEncoding
  def initialize(app)
    @app = app
  end
@jiguang
jiguang / text-align-justify.css
Created December 12, 2012 09:25
两端对齐
.test1 {
text-align:justify;
text-justify:distribute-all-lines;/*ie6-8*/
text-align-last:justify;/* ie9*/
-moz-text-align-last:justify;/*ff*/
-webkit-text-align-last:justify;/*chrome 20+*/
}
@media screen and (-webkit-min-device-pixel-ratio:0){/* chrome*/
.test1:after{
content:".";
@brenes
brenes / model_extension.rb
Last active February 14, 2024 11:39
Removing validation of a model declared on a gem
# We have to remove validations on email, as it's no longer needed.
# Based on a solution found at http://stackoverflow.com/questions/7545938/how-to-remove-validation-using-instance-eval-clause-in-rails
Model.class_eval do
_validators.reject!{ |key, _| key == :field }
_validate_callbacks.each do |callback|
callback.raw_filter.attributes.delete :field
end
@JoostKiens
JoostKiens / compass-HiDPI-images.scss
Last active December 10, 2015 23:38
Cross-browser, slimmed-down Compass media query mixin for high-density images.
/**
* Author: @joostkiens
* Licensed under the MIT license
*/
@mixin hr-image($lr-image, $hr-image) {
background-image: url($lr-image);
@media print,
(-webkit-min-device-pixel-ratio: 1.25),
(-o-min-device-pixel-ratio: 5/4),
(min-resolution: 120dpi) {
@justinbmeyer
justinbmeyer / jsmem.md
Last active June 29, 2024 16:00
JS Memory

JavaScript Code

var str = "hi";

Memory allocation:

Address Value Description
...... ...
@jsl
jsl / strace resque
Created February 9, 2013 11:08
Figuring out what resque processes are doing
In the resque web interface, if you see a process that is hanging for a long
time, you can figure out what it's waiting on by looking at the PID. Say
we see pid 4894 taking a long time. In the console do:
$ sudo strace -p 4894
Process 4894 attached - interrupt to quit
wait4(15045,
The strace just hangs there, and we think that perhaps the process isn't
doing anything. If you look at the man page for wait4, you see that the
@ndarville
ndarville / examples.mdown
Last active December 9, 2019 11:32
“We’ve Been Hacked” Boilerplate Announcement

How Companies Communicated Being Hacked

It’s probably a pretty bad idea to have your site go down, when people are supposed to read the blog post explaining the hack.

Notice how another site reporting the hack received more attention than Twitter’s own announcement. Why was that?