This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationController < ActionController::Base | |
around_filter :gc_disable | |
private | |
def gc_disable | |
GC.disable | |
begin | |
yield | |
ensure |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Foo::Application.routes.draw do | |
constraints(host: /^www\./i) do | |
match '(*any)' => redirect { |params, request| | |
URI.parse(request.url).tap { |uri| uri.host.sub!(/^www\./i, '') }.to_s | |
} | |
end | |
# other routes | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# find all occurrences of $name in the string | |
formula = "$paramname > $value && $x>0" | |
s = formula.gsub(/\$([a-z_\d]+)/) do | |
name = $1 | |
if name=='now' | |
v = Time.now.utc.now | |
else |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// populate data from JSON array | |
public class MyActivity extends Activity { | |
List products; | |
ListView lvProducts; | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.main); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright (C) 2010 The Android Open Source Project | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Main Activity | |
package com.example.mysamples; | |
import android.app.Activity; | |
import android.os.Bundle; | |
import android.widget.AbsListView; | |
import android.widget.GridView; | |
import java.util.ArrayList; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE IF NOT EXISTS `projects` ( | |
`id` int(11) NOT NULL AUTO_INCREMENT, | |
`title` varchar(255) COLLATE utf8_unicode_ci NOT NULL, | |
PRIMARY KEY (`id`) | |
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ; | |
CREATE TABLE IF NOT EXISTS `tasks` ( | |
`id` int(11) NOT NULL AUTO_INCREMENT, | |
`project_id` int(11) NOT NULL, | |
`title` varchar(255) COLLATE utf8_unicode_ci NOT NULL, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :sessions do | |
desc "Clear expired sessions (more than 3 days old)" | |
task :cleanup => :environment do | |
sql = "DELETE FROM sessions WHERE (updated_at < '#{Date.today - 3.days}')" | |
ActiveRecord::Base.connection.execute(sql) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# specific version of Rails, with MySQL database | |
rails _VERSION_ new myapp -d mysql | |
examples: | |
rails _3.2.16_ new myapp -d mysql |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*/10 * * * * /bin/bash -l -c 'cd /var/www/apps/appname/current/ && RAILS_ENV=production bundle exec rake sessions:cleanup >> /var/www/logs/cron.log ' |