Skip to content

Instantly share code, notes, and snippets.

View Paxa's full-sized avatar

Pavel Evstigneev Paxa

View GitHub Profile
ActiveAdmin::Dashboards.build do
# Add this section in your dashboard...
section "Background Jobs" do
now = Time.now.getgm
ul do
li do
jobs = Delayed::Job.where('failed_at is not null').count(:id)
link_to "#{jobs} failing jobs", admin_jobs_path(q: {failed_at_is_not_null: true}), style: 'color: red'
end
@Paxa
Paxa / 0.result for ruby
Last active August 29, 2015 13:58
Ruby and nodejs http library benchmark
[em-http-request, HTTParty, Net::HTTP, Net::HTTP (persistent), open-uri, RestClient, Typhoeus, Excon, Excon (persistent), Curb, Patron (persistent)]
+------------------------+----------+
| tach | total |
+------------------------+----------+
| Patron (persistent) | 0.223029 |
+------------------------+----------+
| Curb | 0.235344 |
+------------------------+----------+
| Typhoeus | 0.389802 |
@Paxa
Paxa / 1.rb
Last active August 29, 2015 14:03
This make class-level method "cached" what makes that method cachable
module CachableMethod
def cachable(merhod_name)
#aliased_merhod_name = :"uncached_#{merhod_name}"
#alias_method aliased_merhod_name, merhod_name
method_proc = instance_method(merhod_name)
ivar_name = :"@#{merhod_name}"
define_method(merhod_name) do |*args, &proc|
if instance_variable_defined?(ivar_name)
@Paxa
Paxa / pg_load.js
Last active August 29, 2015 14:20
node-postgres and node-pg-native
if (pg_native) {
var async = require('async');
pg = {
connect: function (connectString, callback) {
var client = new pg_native;
client.original_query = client.query;
client.sqlQueue = async.queue(function (sql, callback) {
#model
class Comment < ActiveRecord::Base
belongs_to :podcast
validates_presence_of :content
validates_presence_of :author_name
validates_presence_of :podcast_id
validates_length_of :author_name, :within => 2..40
validates_length_of :author_url, :within => 5..200, :allow_blank => true
validates_format_of :author_url, :with => /^[^\"\'\\]*$/,
:message => "can't include backslash or bracket"
class CommentsController < ApplicationController
def create
@podcast = Podcast.find params[:comment][:podcast_id]
params[:comment][:podcast_id] = nil
@comment = @podcast.comments.new params[:comment]
if @comment.save
flash[:notice] = "Comment writen"
redirect_to @podcast
else
@podcast = Podcast.find params[:comment][:podcast_id]
<?
#controller
$bdks = $this->db->select('distinct year as name')->where('site', $_REQUEST['siteid'])->get('pers_to_date')->result();
$this->my_view->view('admin/mailer/filter', array(
'users' => $users,
'total_rows' => $users_num,
'branches' => $this->db->get('branch')->result(), // бля, почему не branches ?
$$('.to_frame').each(function (el) {
var html = el.get('html');
var myIFrame = new IFrame({
src: '',
styles: {
width: el.getStyle('width'),
height: el.getStyle('height').toInt() + 3,
border: 0,
padding: 0
}
def file_tree files, sub = nil, &proc
res = "<ul #{'class="subdir"' if sub }>"
files.each do |file, value|
subdir = (value.class == Hash) ? file_tree(value, 1) { |a, b| proc.call a, b } : nil
res += proc.call file, subdir
end
res + '</ul>'
end
name: "QuickBox"
assets:
css:
- "css/quickbox.css"
js:
quickbox.js: general
a.js: "simple"
b.js: "simple, advaced"
c.js: "specific, advanced"