Skip to content

Instantly share code, notes, and snippets.

View redtachyons's full-sized avatar

Aboobacker MK redtachyons

View GitHub Profile
class Pageviews < ActiveRecord::Base
#google analytics api shenanigans
require 'google/api_client'
require 'date'
include ReportingHelper
def self.getviews post
client, analytics, parameters = ReportingHelper.initclient
parameters = {
@camertron
camertron / asset_preloader.rb
Created June 10, 2017 04:46
Preload assets to make rails dev faster
require 'parallel'
require 'thread'
# The asset preloader is designed to precompute and cache all precompilable
# assets in parallel to avoid doing it in serial on the first request. As of
# Sprockets 3, all assets on the precompile list (i.e. config.assets.precompile)
# are compiled on the first request whether the current page has asked for them
# or not. Obviously such behavior can mean a very slow initial request (we were
# seeing load times on the order of 10-11 minutes). By preloading, or warming the
# sprockets cache, initial page load times can be reduced to ~15 seconds (with
@cobusc
cobusc / postgres_queries_and_commands.sql
Created April 13, 2016 08:23 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(query_start, clock_timestamp()), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(query_start, clock_timestamp()), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@just3ws
just3ws / vcr.rb
Created November 5, 2014 15:02
VCR configuration that does a pretty good job of filtering out GitHub, Twitter, and LinkedIn keys.
VCR.configure do |c|
c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
c.hook_into :webmock
c.ignore_localhost = true
c.default_cassette_options = { record: :new_episodes }
c.allow_http_connections_when_no_cassette = false
c.configure_rspec_metadata!
c.ignore_hosts 'codeclimate.com'
@rmm5t
rmm5t / OUTPUT.md
Last active February 19, 2021 21:18
How to properly introduce a new counter_cache to an existing Rails project.

Fast/efficient approach:

-- execute("UPDATE posts SET comments_count = (SELECT count(1) FROM comments WHERE comments.post_id = posts.id)")
   -> 1.3197s

Slow/naïve approach:

@arnab
arnab / controller.rb
Last active April 6, 2021 15:02
Allow & test CORS requests in Rails
before_filter: allow_cors_requests
def allow_cors
headers["Access-Control-Allow-Origin"] = "*"
headers["Access-Control-Allow-Methods"] = %w{GET POST PUT DELETE}.join(",")
headers["Access-Control-Allow-Headers"] = %w{Origin Accept Content-Type X-Requested-With X-CSRF-Token}.join(",")
head(:ok) if request.request_method == "OPTIONS"
# or, render text: ''
# if that's more your style
end
@authorNari
authorNari / gist:1273387
Created October 9, 2011 06:53
rubyconf2011 note
OK, Let's begin. Hello, Everybody.
My name is Narihiro Nakamura.
Today, I'm talking about "Parallel worlds of CRuby's GC".
I'm very happy now, because I'm meeting attendee in rubyconf.
And, one of my dreams is to talk in rubyconf.
So, I'm very happy and exciting.
Today is my first presentation in English.
My English is not good.
@mikaelhg
mikaelhg / 01_pkcs12-cacerts-workaround.sh
Last active August 4, 2023 06:01
Workaround for java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
# Ubuntu 18.04 and various Docker images such as openjdk:9-jdk throw exceptions when
# Java applications use SSL and HTTPS, because Java 9 changed a file format, if you
# create that file from scratch, like Debian / Ubuntu do.
#
# Before applying, run your application with the Java command line parameter
# java -Djavax.net.ssl.trustStorePassword=changeit ...
# to verify that this workaround is relevant to your particular issue.
#
# The parameter by itself can be used as a workaround, as well.
@rstacruz
rstacruz / index.md
Last active November 3, 2023 09:56
Rails models cheatsheet

Rails Models

Generating models

$ rails g model User

Associations

belongs_to

has_one

@zhengjia
zhengjia / capybara cheat sheet
Created June 7, 2010 01:35
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')