Skip to content

Instantly share code, notes, and snippets.

View dgilperez's full-sized avatar
🌊
Build that!

David Gil dgilperez

🌊
Build that!
View GitHub Profile
@cyx
cyx / gist:3690597
Created September 10, 2012 12:13 — forked from inkel/gist:3690584
Monit Redis
check process redis-server
with pidfile "/var/run/redis.pid"
start program = "/etc/init.d/redis-server start"
stop program = "/etc/init.d/redis-server stop"
if 2 restarts within 3 cycles then timeout
if totalmem > 100 Mb then alert
if children > 255 for 5 cycles then stop
if cpu usage > 95% for 3 cycles then restart
if failed host 127.0.0.1 port 6379 then restart
if 5 restarts within 5 cycles then timeout
@jhjguxin
jhjguxin / 404.html.erb
Created August 13, 2012 05:13
exception catch on rails 3(eg, 400, 403, 500), base on BBTangCMS
<div id="error_page" class="box">
<h1>Ops, 404</h1>
<p>
似乎没有这个页面哦!大哥,去看看别的吧。
</p>
</div>
<!--因为不排除连rails 都无法运行的情况 所以添加 'public/STATUS.htm' 还是很有必要的-->
<!--more>
Finally, the default exceptions application used by Rails that simply renders a page in `public/STATUS.html` is available here: [action_dispatch/middleware/public_exceptions.rb](https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/middleware/public_exceptions.rb)
Remember that whatever you do in the errors controller, it should not be anything “fancy”. Keep it simple because something already went wrong with your application!
@ParkinT
ParkinT / uilabel_adjustable.rb
Created July 8, 2012 04:28
RubyMotion class to auto-size font for text in a multi-line UILabel
class UILabel_Adjustable
# Borrowed and modified the excellent example at http://www.11pixel.com/blog/28/resize-multi-line-text-to-fit-uilabel-on-iphone/
# adapting it for RubyMotion
# This applies only to a multi-line label. You can use '.adjustsFontSizeToFitWidth = true' for a single-line label
# usage is:
# text = "It's bad luck to be superstitious"
# text_label = UILabel.alloc.initWithFrame([[20, 20], [70, 120]])
# text_label.numberOfLines = 0 # set 0 for word wrap
# text_label.lineBreakMode = UILineBreakModeWordWrap
@sj26
sj26 / wysihtml5_helper.rb
Created May 28, 2012 06:32
Helper for capybara to fill in wysihtml5 fields respecting `within` scopes
module Wysihtml5Helper
def fill_in_html name, options
options.to_options!.assert_valid_keys :with
if Capybara.current_driver == Capybara.javascript_driver
# Dip inside capybara session to respect current `within` scope
scope = page.send(:current_node).path
# Find the textarea based on label name within the given scope
query = "$('label:contains(#{name.inspect}) ~ textarea:eq(0)', document.evaluate(#{scope.inspect}, document).iterateNext())"
# Make sure the editor is instantiated -- this is us, not wysihtml5
wait_until { page.evaluate_script("!!#{query}.data('editor')") }
@chsh
chsh / appapp_delegate.rb
Created May 10, 2012 08:41
RubyMotion Localization sample.
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
alert = UIAlertView.new
alert.message = t('start')
alert.show
true
end
def t(key)
NSBundle.mainBundle.localizedStringForKey(key, value:nil, table:nil)
@panthomakos
panthomakos / benchmark.rb
Created May 3, 2012 20:06
Benchmark Your Bundle
#!/usr/bin/env ruby
require 'benchmark'
REGEXPS = [
/^no such file to load -- (.+)$/i,
/^Missing \w+ (?:file\s*)?([^\s]+.rb)$/i,
/^Missing API definition file in (.+)$/i,
/^cannot load such file -- (.+)$/i,
]
@tjh
tjh / character_set_and_collation.rb
Created January 31, 2012 16:07
Convert all Rails table column collation and character set
#!/usr/bin/env ruby
# Put this file in the root of your Rails project,
# then run it to output the SQL needed to change all
# your tables and columns to the same character set
# and collation.
#
# > ruby character_set_and_collation.rb
DATABASE = ''
@bsodmike
bsodmike / gist:1698390
Created January 29, 2012 11:32
git diff between Rails 3.2.0 and Rails 3.1.0 generated apps
diff --git a/.gitignore b/.gitignore
index 923b697..eb3489a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,15 @@
-.bundle
-db/*.sqlite3
-log/*.log
-tmp/
-.sass-cache/
@furi2
furi2 / gist:1378595
Created November 19, 2011 07:36
Uploading multipart/form-data type data from Titanium
var content = '';
var boundary = '---------------------------170062046428149';
content += '--'+ boundary + '\r\n';
content += 'Content-Disposition: form-data; name="uploadToken"\r\n';
content += '\r\n';
content += upload_token + '\r\n';
content += '--'+ boundary + '\r\n';
content += 'Content-Disposition: form-data; name="destFolderPath"\r\n';
content += '\r\n';
@tddium
tddium / capybara_debug.rb
Created November 16, 2011 19:54
Trap Capybara Stack Trace
### Show stack trace for 500 errors
### (adapted from https://gist.github.com/1079020)
# Given an application, yield to a block to handle exceptions
class ExceptionRaiserApp
def initialize(app)
@app = app
end
def call(env)