Skip to content

Instantly share code, notes, and snippets.

@austra
austra / gist:868e06718c00ffee70d2
Created February 11, 2015 20:10
confimation before ajax request
$('.removeItem').click(function (event) {
if (confirm('Are you sure you want to delete this?')) {
$.ajax({
url: 'myUrl',
type: "POST",
data: {
// data stuff here
},
success: function () {
// does some stuff here...
@austra
austra / gist:51191fe7fd043ae31ae8
Created March 9, 2015 16:33
rails jquery unobtrusive onclick
Obtrusive:
link_to 'Another link with obtrusive JavaScript', '#',
:onclick => 'alert("Please no!")'
Unobtrusive:
rails:
link_to 'Link with unobtrusive JavaScript',
@austra
austra / gist:4a299cd9dd94794a36e0
Created April 2, 2015 01:28
redis expiration listener
def start_listener()
uri = URI.parse(ENV["REDISCLOUD_URL"])
redis = Redis.new(host: uri.host, port: uri.port, password: uri.password)
Thread.new do
begin
redis.subscribe("__keyevent@0__:expired") do |on|
on.subscribe do |channel, subscriptions|
puts "Subscribed to ##{channel} (#{subscriptions} subscriptions)"
end
@austra
austra / gist:895d0fc7f450658fc564
Created April 9, 2015 23:08
git log searching
To search the commit log (across all branches) for the given text:
git log --all --grep='my commit message'
To search the actual content of commits through a repo's history, use:
git grep 'my commit message' $(git rev-list --all)
rsync -avzP -e "ssh -i /home/user/my.pem" [email protected]:/home/ubuntu/remote-dir /home/user/local-dir
@austra
austra / gist:d8f5a1de00f12c253716
Last active July 12, 2020 21:33
Pagination Headers With Kaminari for API
http://jaketrent.com/post/pagination-headers-with-kaminari/
https://developer.github.com/v3/#pagination
Kaminari provides easy pagination in a rails app. It’s great to use. We’ll make it better by adding a little function to your controllers to provide useful pagination headers.
kaminari pagination
Pagination from Kaminari
@austra
austra / gist:53721da86b149718160b
Created October 26, 2015 21:01 — forked from deevis/gist:359741f1e498da14f9e3
Choose multiple files from current branch as the 'merge conflict winner'
# All the files that match with 'coverage' and tell git to use the branch we're on currenthl (ours, opposed to theirs)
git status | grep coverage | sed 's/.*: \(.*\)/\1/g' | xargs git checkout --ours
@austra
austra / gist:07225957f9f173fff422
Created October 26, 2015 21:01 — forked from deevis/gist:61113a95429e219fd108
Parse Vibe logs for slowest showing time to render, user, path, and time of request
zgrep "END: current_user" production.log.2.gz | sed 's/\(.*\) \[.*INFO.*current_user\[\(.*\)\] (\(.*\)) \(.*\)/\3\t\4\t\2\t\1/g' | sort -n | tail -n 20
# with process:request
grep "END: current_user" production.log | sed 's/\(.*\) \[.*INFO.*\[\(.*\)\].*current_user\[\(.*\)\] (\(.*\)) \(.*\)/\4\t\2\t\1\t\3\t\5/g' | sort -n | tail -n 100
# find with process:request, then loop back and find problems for each...
# Part 1
grep "END: current_user" production.log | sed 's/\(.*\) \[.*INFO.*\[\(.*\)\].*current_user\[\(.*\)\] (\(.*\)) \(.*\)/\4\t\2\t\1\t\3\t\5/g' | sort -n | tail -n 100 > slow_requests_10_26_2015.txt
# Part 2
for rqid in `cat slow_requests_10_26_2015.txt | sed 's/.*seconds\t\(.*\)\s.*2015.*/\1/g'`;do echo -e "API Calls for [$rqid]\n---------------------------\n"; grep $rqid production.log | grep "request to api.exigo.com" -A 1; echo -e "\n\n";done > exigo_slow_calls_report_10_26_2015.txt
@austra
austra / gist:7dc8429145d386499872
Created October 27, 2015 14:57 — forked from deevis/gist:b4f71ba52067531575ca
Get list of users with occurrence count who had a certain type of error occur
for request in `grep -e "undefined local variable or method .*html_safe" log/production.log -B 1 | grep FATAL | sed 's/.*FATAL.*\[\(.*\)\]/\1/g'`;do grep "$request" log/production.log | head -n 20 | grep current_user;done | sed 's/.*current_user\(.*\).*/\1/g' | sort | uniq -c | sort -n
@austra
austra / gist:f9f3f3364760efda320d
Created October 28, 2015 16:04
ActiveRecord::Base.connection
raw = ActiveRecord::Base.connection.execute(sql)
raw.each(:as => :hash) do |row|
puts row.inspect # row is hash
end