Skip to content

Instantly share code, notes, and snippets.

module MultiParameterAttributes
def filter_time(attributes, name)
attrs = attributes.collect do |key, value|
if key =~ /^#{Regexp.escape(name.to_s)}\((\d+)(\w)\)$/
[$1.to_i, value.send("to_#$2")]
end
end.compact.sort_by(&:first).map(&:last)
Time.zone.local(*attrs) unless attrs.empty?
end
anonymous
anonymous / example2.js
Created April 29, 2011 03:37
MongoDB map reduce example 2
// suggested shell cmd line to run this:
//
// mongo --shell example2.js
//
// Note: the { out : … } parameter is for mongodb 1.8+
db.things.insert( { _id : 1, tags : ['dog', 'cat'] } );
db.things.insert( { _id : 2, tags : ['cat'] } );
db.things.insert( { _id : 3, tags : ['mouse', 'cat', 'dog'] } );
db.things.insert( { _id : 4, tags : [] } );
@stevenwanderski
stevenwanderski / active_admin.css.scss
Created April 11, 2013 06:50
Prevent Active Admin from clobbering CKEditor CSS styles
// SASS variable overrides must be declared before loading up Active Admin's styles.
//
// To view the variables that Active Admin provides, take a look at
// `app/assets/stylesheets/active_admin/mixins/_variables.css.scss` in the
// Active Admin source.
//
// For example, to change the sidebar width:
// $sidebar-width: 242px;
// Active Admin's got SASS!
@loicginoux
loicginoux / gist:5577498
Created May 14, 2013 16:50
paste this into your app/assets/stylesheets/active_admin.css.scss to get Rich editor styling correct in Active Admin
body.active_admin {
.cke_chrome {
width: 76% !important;
overflow: hidden;
}
.cke_dialog_background_cover{
background-color: black !important;
}
}
body.active_admin {
@hugohernani
hugohernani / ar_model_required_attrs.rb
Created March 11, 2016 17:47
Get Attributes which presence validator was added to a model_(instance|klass)
def required_attributes(obj)
target = obj.class == Class ? obj : obj.class
target.validators.select do |amv|
amv.class == ActiveRecord::Validations::PresenceValidator
end.map(&:attributes).flatten
end
@jlecour
jlecour / init_unicorn.sh
Created June 25, 2012 13:39
Unicorn configuration
#!/bin/bash
set -e
### BEGIN INIT INFO
# Provides: unicorn
# Required-Start: $all
# Required-Stop: $network $local_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
@dazoakley
dazoakley / passenger_process_monitor.rb
Created January 6, 2012 10:28
Script for killing errant passenger processes
#!/usr/bin/env ruby
#
# Passenger Process Monitor
#
# By Darren Oakley
# Based heavily on a script by James Smith (https://gist.github.com/851520)
# That in turn was based on a similar script by Jon Bettcher
#
# - Check memory usage of all paseenger child process and kill if grows too large.
@manfe
manfe / helper.rb
Last active January 14, 2020 10:15
Rails Helper to build Hierachical HTML List
module TreeListHelper
# the collection need to be the root parents
def tree_list(collection)
content_tag(:ul) do
collection.each do |item|
if item.children.any?
concat(
content_tag(:li, id: item.id) do
concat(item.name)
concat(tree_list(item.children))
@jarednorman
jarednorman / webpack-rails-1.markdown
Last active May 13, 2020 18:24
Webpack with Rails Part 1

Webpack with Rails Part 1

I don't like Sprockets, but it's the easiest and best choice for lots of Ruby on Rails projects. When looking for a better way to manage my JavaScript assets and an improved developer story, my current tool of choice is webpack. While I wish Rails supported drop-in asset pipelines the way that Phoenix does, it's not hard to use webpack with Rails.

@erluxman
erluxman / rectangularnotch.dart
Created April 28, 2020 02:28
Rectangular notched Fab
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(