Skip to content

Instantly share code, notes, and snippets.

@oguya
oguya / !request_user_id.py
Created December 5, 2013 12:25
get userid without using request object
from django.contrib.auth.models import User
User.objects.get(username=the_username).pk
@oguya
oguya / imageLoader.java
Created January 6, 2014 07:45
Load image from URL to an ImageView
//ImageLoader lib => http://search.maven.org/remotecontent?filepath=com/novoda/imageloader/imageloader-core/1.5.8/imageloader-core-1.5.8.jar
String image_url = "http://mycodeandlife.files.wordpress.com/2013/01/384088_2317070728022_2086719259_n.jpg";
ImageView image = (ImageView) findViewById(R.id.imageView1);
// Get singletone instance of ImageLoader
ImageLoader imageLoader = ImageLoader.getInstance();
// Initialize ImageLoader with configuration. Do it once.
imageLoader.init(ImageLoaderConfiguration.createDefault(this));
// Load and display image asynchronously
DisplayImageOptions options = new DisplayImageOptions.Builder()
@oguya
oguya / uploadFile_java.java
Last active January 3, 2016 00:28
upload file in java to server side php
public static void uploadFile(String filePath, String serverURL) throws IOException {
HttpClient httpClient = new DefaultHttpClient();
//post request to send file
HttpPost httpPost = new HttpPost(serverURL);
// StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
// StrictMode.setThreadPolicy(policy);
FileBody uploadFile = new FileBody(new File(filePath));
MultipartEntity reqEntity = new MultipartEntity();
// reqEntity.addPart("the args. the server takes", uploadFile);
@oguya
oguya / uploaded_files.php
Created January 12, 2014 09:04
receive uploaded file...crud
<?php
$storage = $_SERVER['DOCUMENT_ROOT'].'/droid/uploads/';
#check uploaded file status
if(is_uploaded_file($_FILES['uploaded_file']['tmp_name'])){
echo "\nfile successfully uploaded!\n";
}else{
echo "\nfile not uploaded!\n";
exit;
@oguya
oguya / RobotoFonts.java
Created January 13, 2014 12:46
Add roboto fonts in textviews android
Typeface tf = Typeface.createFromAsset(getAssets(),"fonts/Roboto-Black.ttf");
TextView tv = (TextView) findViewById(R.id.FontTextView);
tv.setTypeface(tf);
{
"ANDROID_VERSION": 1.5,
"APP_VERSION_CODE": 8,
"APP_VERSION_NAME": 1.3,
"AVAILABLE_MEM_SIZE": 181972992,
"BRAND": "generic",
"BUILD": {
"BOARD": "unknown",
"BRAND": "generic",
"DEVICE": "generic",
@oguya
oguya / build.gradle
Created January 29, 2014 16:38
Spring gradle configs
dependencies {
compile 'org.springframework.android:spring-android-rest-template:1.0.1.RELEASE'
compile 'org.springframework.android:spring-android-auth:1.0.1.RELEASE'
compile 'org.springframework.android:spring-android-core:1.0.1.RELEASE'
}
@oguya
oguya / fontSetter.java
Created January 30, 2014 08:51
set custom fonts in java
public class MyApplication extends Application {
private Typeface normalFont;
private Typeface boldFont;
//FontSetter fontSetter = (FontSetter) getApplication();
//TextView myTextView = (TextView) findViewById(R.id.my_textview);
//application.setTypeface(myTextView);
@oguya
oguya / ScreenLayoutSize.java
Created February 9, 2014 08:10
load different layouts depending on screensize
if((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_LARGE) == Configuration.SCREENLAYOUT_SIZE_LARGE){
//load a large screen layout
}else{
//load a default screen layout
}
public class saveAsParcel implements Parcelable {
private String myStringValue;
public PassableObject() {}
public PassableObject(Parcel inParcel) {
myStringValue = inParcel.readString();
}
@Override