Skip to content

Instantly share code, notes, and snippets.

rocLv rocLv

Block or report user

Report or block rocLv

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@rocLv
rocLv / install_sentry.sh
Created Feb 25, 2019 — forked from bjmc/install_sentry.sh
Basic setup script for installing Sentry (http://getsentry.com) + Redis on new Ubuntu 14.04 Amazon EC2 instance
View install_sentry.sh
#! /bin/bash
export RUN_AS='ubuntu';
export INSTALL_DIR='/var/www/sentry';
HOSTNAME='http://mysentry.example.com'; # No trailing slash
DB_HOST='something.rds.amazonaws.com';
DB_PORT='5432';
DB_USER='sentry';
DB_NAME='sentry';
DB_PASSWORD='DB_PASSWORD';
@rocLv
rocLv / rails.ipynb.json
Created Apr 25, 2018 — forked from l15n/rails.ipynb.json
Rails and Jupyter
View rails.ipynb.json
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
View gist:9c99516d6225a8c3b305c0d7c8d180b5

Rails naming conventions

General Ruby conventions

Class names are CamelCase.

Methods and variables are snake_case.

Methods with a ? suffix will return a boolean.

@rocLv
rocLv / beautiful_idiomatic_python.md
Created Nov 11, 2017 — forked from JeffPaine/beautiful_idiomatic_python.md
Transforming Code into Beautiful, Idiomatic Python: notes from Raymond Hettinger's talk at pycon US 2013. The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!
View beautiful_idiomatic_python.md

Transforming Code into Beautiful, Idiomatic Python

Notes from Raymond Hettinger's talk at pycon US 2013 video, slides.

The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!

Looping over a range of numbers

for i in [0, 1, 2, 3, 4, 5]:
View application.rb
require_relative 'boot'
require 'csv'
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module Giant
class Application < Rails::Application
View json_helper.rb
module RequestHelper
def json_response
JSON.parse(response.body, symbolize_names: true)
end
end
class ActionDispatch::IntegrationTest
include RequestHelper
end
@rocLv
rocLv / redis.rb
Created Apr 19, 2017 — forked from pubis/redis.rb
Redis config and initialization for rails
View redis.rb
#config/initializers/redis.rb
require 'redis'
require 'redis/objects'
REDIS_CONFIG = YAML.load( File.open( Rails.root.join("config/redis.yml") ) ).symbolize_keys
dflt = REDIS_CONFIG[:default].symbolize_keys
cnfg = dflt.merge(REDIS_CONFIG[Rails.env.to_sym].symbolize_keys) if REDIS_CONFIG[Rails.env.to_sym]
$redis = Redis.new(cnfg)
Redis::Objects.redis = $redis
View ai.rb
require 'curb'
require "json"
require "base64"
require "net/http"
require "uri"
CUID = "8132533";
CLIENT_ID = "your_client_id";
CLIENT_SECRET = "your_client_secret";
@rocLv
rocLv / company.rb
Created Apr 18, 2017 — forked from davinmsu/company.rb
remove duplicates from activerecord
View company.rb
def self.dedupe
# find all models and group them on keys which should be common
grouped = all.group_by{|model| [model.title,model.info,model.address,model.phone] }
grouped.values.each do |duplicates|
# the first one we want to keep right?
first_one = duplicates.shift # or pop for last one
# if there are any more left, they are duplicates
# so delete all of them
duplicates.each{|double| double.destroy} # duplicates can now be destroyed
end
@rocLv
rocLv / custom_logger.rb
Created Apr 7, 2017 — forked from kinopyo/custom_logger.rb
Custom logger file in Rails
View custom_logger.rb
# lib/custom_logger.rb
class CustomLogger < Logger
def format_message(severity, timestamp, progname, msg)
"#{timestamp.to_formatted_s(:db)} #{severity} #{msg}\n"
end
end
logfile = File.open("#{Rails.root}/log/custom.log", 'a') # create log file
logfile.sync = true # automatically flushes data to file
CUSTOM_LOGGER = CustomLogger.new(logfile) # constant accessible anywhere
You can’t perform that action at this time.