Skip to content

Instantly share code, notes, and snippets.

View Richie97's full-sized avatar

Eric Richardson Richie97

View GitHub Profile
@app.route('/locations/add', methods=['POST'])
def add_loc():
db.execute('insert into locations(name, blurb, phone_number, address, url) values(?,?,?,?,?)', [request.form['name'], request.form['blurb'], request.form['phone'], request.form['address'], request.form['url']])
db.commit()
return
class CheckIn(db.Model):
__tablename__ = 'checkins'
id = db.Column(db.Integer, primary_key=True)
location_id = db.Column(db.Integer)
user_id = db.Column(db.Integer)
date = db.Column(db.DateTime)
def to_dict(self):
return{
@Richie97
Richie97 / gist:2004295
Created March 9, 2012 00:19
immutable Bitmap into mutable bitmap.
public static Bitmap convertToMutable(Bitmap imgIn) {
try {
//this is the file going to use temporally to save the bytes.
// This file will not be a image, it will store the raw image data.
File file = new File(Environment.getExternalStorageDirectory() + File.separator + "temp.tmp");
//Open an RandomAccessFile
//Make sure you have added uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
//into AndroidManifest.xml file
RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw");
@Richie97
Richie97 / gist:2008332
Created March 9, 2012 19:54
Resizing Bitmaps
public Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) {
int width = bm.getWidth();
int height = bm.getHeight();
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
@Richie97
Richie97 / androidTabletChecker
Created April 12, 2012 21:49
Tablet Checker
/**
* Checks if the device is a tablet or a phone
*
* @param activityContext
* The Activity Context.
* @return Returns true if the device is a Tablet
*/
public static boolean isTabletDevice(Context activityContext) {
// Verifies if the Generalized Size of the device is XLARGE to be
// considered a Tablet
@Richie97
Richie97 / Tabletcheck2
Created April 13, 2012 19:55
More Tablet checking code
public boolean isTablet(Context context) {
boolean xlarge = ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == 4);
boolean large = ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE);
return (xlarge || large);
}
@Richie97
Richie97 / gist:3006339
Created June 27, 2012 19:47
Custom View onClick
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getSupportMenuInflater();
inflater.inflate(R.menu.entry_menu, menu);
MenuItem mItem = menu.findItem(R.id.menu_comments);
commentCount = (TextView)mItem.getActionView().findViewById(R.id.actionEntryCommentCount);
commentCount.setText(Integer.toString(article.numComments));
mItem.getActionView().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@Richie97
Richie97 / wireshark on device
Created July 10, 2012 20:57
Enable WireShark type stuff for Logcat
**Paste this shiz where you need to troubleshoot*****************************************************
java.util.logging.Logger.getLogger("org.apache.http.wire").setLevel(java.util.logging.Level.FINEST);
java.util.logging.Logger.getLogger("org.apache.http.headers").setLevel(java.util.logging.Level.FINEST);
System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true");
System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire", "debug");
System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http", "debug");
System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.headers", "debug");
@Richie97
Richie97 / gist:3286131
Created August 7, 2012 15:05
Broadcast Receiver Stuff
public class ButtonStuff extends BaseButtonStuff {
private boolean whatevs;
//Broadcast Receiver
private BroadcastReceiver br = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
updateShit();
}
};
//Do them SlidingMenu as so
SlidingMenu menu;
private void setUpSideMenu(){
menu = new SlidingMenu(this);
menu.setMenu(R.layout.side_menu);
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
menu.setBehindOffsetRes(R.dimen.actionbar_home_width);
menu.setBehindScrollScale(0.25f);
menu.setShadowDrawable(R.drawable.shadow);