Skip to content

Instantly share code, notes, and snippets.

@StlTenny
StlTenny / gist:1981303
Created March 5, 2012 21:43
StlTenny Models
class Message < ActiveRecord::Base
belongs_to :user
accepts_nested_attributes_for :user
end
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
@StlTenny
StlTenny / RestServiceActivity.java
Created March 14, 2012 19:22
Sample RestService Implementation Snippet
RestService restService;
restService = new RestService(mHandler, this, "http://10.0.2.2:3000/bars/");
restService.addParam("lat", "40764917"); //Add params to request
restService.addParam("lng", "-73983130");
restService.addParam("range", "10");
restService.addHeader("Content-Type","application/json");//Add headers to request
//Overridden handler to process incoming response.
private final Handler mHandler = new Handler(){
@StlTenny
StlTenny / ftp.java
Created March 23, 2012 21:38
FTP Upload
private static void check(FTPClient ftp, String cmd, boolean succeeded) throws IOException {
if (!succeeded) {
throw new IOException("FTP error: " + ftp.getReplyString());
}
}
private static String today() {
return new SimpleDateFormat("yyyy-MM-dd").format(new Date());
}
@StlTenny
StlTenny / SMSLauncher.java
Created March 28, 2012 15:33
Upload files from Android via FTP
public class SMSLauncher extends BroadcastReceiver
{
public static final String SMS_EXTRA_NAME = "pdus";
@Override
public void onReceive(Context context, Intent intent)
{
Bundle extras = intent.getExtras();
String messages = "";
@StlTenny
StlTenny / ApiBuilderTrap.java
Created April 4, 2012 19:19
Circle Packing Problem
package googleApiBuilder;
public class ApiBuilderTrap {
public static void main(String args[]){
String query = "";
int x = -74008713;
int y = 40752459;
int yint = 40752459;
double efficiency = .9069;
@StlTenny
StlTenny / example.java
Created June 14, 2012 15:07
RestService ProgressDialog Example
RestService restServiceG;
//Create the progress dialog and show it, before running your restService request
Final ProgressDialog dialog = new ProgressDialog(mContext);
dialog.setMessage("Please wait.. Retrieving");
dialog.setIndeterminate(true);
dialog.setCancelable(true);
dialog.show();
@StlTenny
StlTenny / gist:2938258
Created June 15, 2012 19:13
Small Script
<% [:error].each do |level| %>
<% unless flash[level].blank? %>
<script type="text/javascript">
$('#myModal').modal('show')
</script>
<% end %>
Started POST "/customers/3/tabs" for 127.0.0.1 at Mon Jun 18 14:02:36 -0400 2012
Processing by TabsController#create as HTML
Parameters: {"commit"=>"Create Tab", "authenticity_token"=>"2bJBuyENTUg/lOLjU7s1WdCESTAYEFM/CroNCWFWAWE=", "customer_id"=>"3", "tab"=>{"is_open"=>"1", "current_price"=>"0", "closed_price"=>"0", "bar_id"=>""}, "utf8"=>"✓"}
SQL (0.5ms) INSERT INTO "tabs" ("bar_id", "closed_price", "created_at", "current_price", "customer_id", "is_open", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?) [["bar_id", nil], ["closed_price", 0], ["created_at", Mon, 18 Jun 2012 18:02:36 UTC +00:00], ["current_price", 0], ["customer_id", nil], ["is_open", true], ["updated_at", Mon, 18 Jun 2012 18:02:36 UTC +00:00]]
Redirected to http://localhost:3000/tabs/4
Completed 302 Found in 12ms
#Tab Controller
def new
import sublime_plugin
class NextGroup(sublime_plugin.WindowCommand):
def run(self):
numGroups = self.window.num_groups()
currentGroup = self.window.active_group()
if currentGroup < numGroups - 1:
newGroup = currentGroup + 1
else:
import sublime_plugin
class NextViewInGroup(sublime_plugin.WindowCommand):
def run(self):
currentGroup, currentViewIndex = self.window.get_view_index(self.window.active_view())
currentViews = self.window.views_in_group(currentGroup)
if currentViewIndex < len(currentViews) - 1:
newView = currentViews[currentViewIndex + 1]
else: