Skip to content

Instantly share code, notes, and snippets.

View katpadi's full-sized avatar
🎯
Focusing

Kat Padilla katpadi

🎯
Focusing
View GitHub Profile
@katpadi
katpadi / ExceptionsHandler
Last active August 29, 2015 14:09
Exceptions Handler
module API
module V1
module ExceptionsHandler
extend ActiveSupport::Concern
included do
rescue_from ActiveRecord::RecordNotFound do |e|
error_response(message: e.message, status: 404)
end
Sun Apr 12 23:33:52 PHT 2015: PING google.com (120.28.26.227) 56(84) bytes of data.
Sun Apr 12 23:33:52 PHT 2015: 64 bytes from 120.28.26.227: icmp_seq=1 ttl=57 time=34.6 ms
Sun Apr 12 23:33:53 PHT 2015: 64 bytes from 120.28.26.227: icmp_seq=2 ttl=57 time=34.6 ms
Sun Apr 12 23:33:54 PHT 2015: 64 bytes from 120.28.26.227: icmp_seq=3 ttl=57 time=33.7 ms
Sun Apr 12 23:33:55 PHT 2015: 64 bytes from 120.28.26.227: icmp_seq=4 ttl=57 time=37.1 ms
Sun Apr 12 23:33:56 PHT 2015: 64 bytes from 120.28.26.227: icmp_seq=5 ttl=57 time=35.3 ms
Sun Apr 12 23:33:57 PHT 2015: 64 bytes from 120.28.26.227: icmp_seq=6 ttl=57 time=36.3 ms
Sun Apr 12 23:33:58 PHT 2015: 64 bytes from 120.28.26.227: icmp_seq=7 ttl=57 time=34.4 ms
Sun Apr 12 23:33:59 PHT 2015: 64 bytes from 120.28.26.227: icmp_seq=8 ttl=57 time=39.2 ms
Sun Apr 12 23:34:00 PHT 2015: 64 bytes from 120.28.26.227: icmp_seq=9 ttl=57 time=33.2 ms
@katpadi
katpadi / timelapse_shooter.sh
Last active August 29, 2015 14:23
timelapse_shooter
#!/bin/sh
OPTIONS='-hf -vf -o'
TS=$(date +%Y-%m-%d_%T)
# Take a snapshot
raspistill $OPTIONS "$TS".jpg
# For now this is the filename
file="$TS.jpg"
@katpadi
katpadi / convert_and_upload.sh
Created June 29, 2015 09:33
timelapse_converter
#!/bin/sh
# Collect the jpg's
ls *.jpg stills.txt
# Create the video (mencoder)
mencoder -nosound -ovc lavc -lavcopts vcodec=mpeg4:aspect=16/9:vibrate=8000000 -vf scale=1920:1080 -o timelapse.avi -mf type=jpeg:fps=24 mf://@stills.txt
# TODO: Upload to YouTube?
answer['attributes']['name']
answer['attributes']['name']
@katpadi
katpadi / active_record_descendant_class.rb
Created October 31, 2015 18:54
active_record_descendant_class
# Returns the class descending directly from ActiveRecord::Base in the inheritance hierarchy.
def active_record_descendant_class(klass)
if klass == ActiveRecord::Base || klass.superclass == ActiveRecord::Base
klass
elsif klass.superclass.nil?
fail "#{name} doesn't belong in a hierarchy descending from ActiveRecord"
else
active_record_descendant_class(klass.superclass)
end
end
class StellarLogger < Logger
def format_message(severity, timestamp, progname, msg)
"#{timestamp.to_formatted_s(:db)} #{severity} #{msg}\n"
end
end
logfile = File.open("#{Rails.root}/log/stellar.log", 'a') # create log file
logfile.sync = true # automatically flushes data to file
STELLAR_LOGGER = StellarLogger.new(logfile)
@katpadi
katpadi / katpadi.sublime-mousemap
Created July 12, 2016 11:41
command + click to goto_definition
# Sublime CTags Mouse Map Command + Click to Go to definition
# Mac - create "Default (OSX).sublime-mousemap" in ~/Library/Application Support/Sublime Text 3/Packages/User
[
{
"button": "button1",
"count": 1,
"modifiers": ["command"],
"command": "goto_definition",
"press_command": "drag_select"
@katpadi
katpadi / .rubocop.yml
Created July 13, 2016 08:09
Kat's Preferred RuboCop Style Guide
Documentation:
Enabled: false
AllCops:
Include:
- '**/Rakefile'
- '**/config.ru'
Exclude:
- 'db/**/*'
- 'test/test_helper.rb'
- 'spec/spec_helper.rb'
{
"auto_complete_commit_on_tab": true,
"caret_style": "solid",
"color_scheme": "Packages/User/RailsCastsColorScheme (SL).tmTheme",
"draw_white_space": "all",
"enable_tab_scrolling": false,
"ensure_newline_at_eof_on_save": true,
"file_exclude_patterns":
[
"*.pyc",