Skip to content

Instantly share code, notes, and snippets.

@a2f0
a2f0 / gist:6032220
Last active December 19, 2015 23:08
nginx logrorate
/var/log/nginx/*.log {
daily
compress
delaycompress
rotate 7
missingok
sharedscripts
postrotate
test ! -f /var/run/nginx.pid || kill -USR1 `cat /var/run/nginx.pid`
touch /opt/rails/asap/app/2014/current/tmp/restart.txt
@a2f0
a2f0 / gist:7553611
Created November 19, 2013 22:20
with rvm
# pstree -p
init(1)-+-PassengerWatchd(14233)-+-PassengerHelper(14236)-+-ruby(14262)-+-ruby(14386)-+-{ruby}(14388)
| | | | |-{ruby}(14391)
| | | | `-{ruby}(14392)
| | | |-{ruby}(14387)
| | | `-{ruby}(14389)
| | |-{PassengerHelpe}(14238)
| | |-{PassengerHelpe}(14239)
| | |-{PassengerHelpe}(14240)
| | |-{PassengerHelpe}(14243)
Migration:
class CreateJoinTableCommandTag < ActiveRecord::Migration
def change
create_join_table :commands, :tags do |t|
# t.index [:command_id, :tag_id]
# t.index [:tag_id, :command_id]
end
end
@a2f0
a2f0 / gist:8553481
Last active January 4, 2016 02:09
destroy always fail
Here is the command that I can execute against it (the one that I think I should *not* be able to execute. I basically am trying to write a more complex validation that prevents deletion of a tag based on more complex criteria, but would like to first write a base before_destroy validation that causes the deletion to *always* fail no matter what.
@command = Command.find(params[:id])
tag = Tag.find(params[:tag_id])
@command.tags.delete(tag)
Here is the complete model for tagmapsorter:
class Tagmapsorter < ActiveRecord::Base
belongs_to :command
Would somebody be able to tell me why these queries are giving me different results when I am executing the same query? I am executing one in active record and one natively via SQLite.
SQLite:
sqlite> select * from commands LEFT OUTER JOIN tagmapsorters ON tagmapsorters.command_id = commands.id WHERE tagmapsorters.tag_id is NULL;
3|hi|2014-01-24 07:07:20.149017|2014-01-24 07:07:20.149017|hi|||||
sqlite> select * from commands;
2|unix|2014-01-24 06:47:51.701648|2014-01-24 06:47:51.701648|unix
3|hi|2014-01-24 07:07:20.149017|2014-01-24 07:07:20.149017|hi
4|linux|2014-01-24 07:41:29.121709|2014-01-24 07:41:29.121709|whatever
Started GET "/admin/employees/645114968/blogposts" for 127.0.0.1 at 2014-07-28 17:40:10 -0500
Processing by Admin::BlogpostsController#index as HTML
Parameters: {"employee_id"=>"645114968"}
AdminUser Load (0.2ms) SELECT "admin_users".* FROM "admin_users" WHERE "admin_users"."id" = 1 LIMIT 1
Completed 500 Internal Server Error in 3ms
NoMethodError (undefined method `find' for nil:NilClass):
inherited_resources (1.5.0) lib/inherited_resources/belongs_to_helpers.rb:90:in `evaluate_parent'
inherited_resources (1.5.0) lib/inherited_resources/base_helpers.rb:144:in `block in association_chain'
inherited_resources (1.5.0) lib/inherited_resources/base_helpers.rb:143:in `each'
p = subprocess.Popen(["mysqldump", "--single-transaction", "-u",
database_username, "--password="+database_password, "--databases",
"--host", server_address, database_name, ],
stdout = open( outputfile, 'w') , stderr=subprocess.PIPE)
error = p.stderr.read()
p_ret = p.wait()
print "return code from mysqldump: " + str(p_ret)
if (len(error)) > 0:
action_error(error)
@a2f0
a2f0 / gist:3dbf7a087a42373a6407
Last active August 29, 2015 14:05
detect hung passenger processes by inspecting an isolated application pool, iterating, and authing against the api
#!/bin/sh
#Isolate an application pool and iterate through and authenticate
#Written by Dan Sullivan
#Will detect hung processes
IFS=$'\n'
for i in $(rvmsudo passenger-status --verbose |
pcregrep -M '/opt(.|\n)*^/opt' |
grep -v Requests | grep -v ^/ |
grep -v "App root" | grep -v CPU |
@a2f0
a2f0 / gist:6371c0ab2d72d555cd7c
Created August 28, 2014 07:04
awesome SVG example
<!DOCTYPE html>
<html>
<head>
<title>This shows how to get elements inside included svg images from the surrounding html.</title>
</head>
<body>
<object class="emb" data="images/svglogo.svg" width="100" height="100" type="image/svg+xml"></object>
<embed class="emb" src="images/svglogo.svg" width="100" height="100" type="image/svg+xml" />
<iframe class="emb" src="images/svglogo.svg" width="100" height="100" style="border:0" ></iframe>
<p>
@a2f0
a2f0 / gist:5d8309046e5ec1ae55dd
Created September 13, 2014 20:10
javascript star code
<script>//<![CDATA[
window.addEventListener("load", configRainbow, false);
function configRainbow() {
var x=document.getElementById("rainy");
var bigstar;
if (x.contentDocument) {
var star1 = x.contentDocument.getElementById("star1");
var star2 = x.contentDocument.getElementById("star2");
var star3 = x.contentDocument.getElementById("star3");
var star4 = x.contentDocument.getElementById("star4");