Skip to content

Instantly share code, notes, and snippets.

@bofh19
bofh19 / onscrollchanged.java
Created August 5, 2013 07:57
android on scroll state changed ... loading data when over scrolled
private Boolean loading_data = false;
private Boolean load_data = false;
private OnScrollListener mScrollListener = new OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
if(load_data && !loading_data){
startLoadingData();
}
}
@bofh19
bofh19 / template.html
Created July 22, 2013 12:14
DJANGO multiple file uploads at once... javascript method ... NOT HTML5 Drag and drop upload. although this method may be improved to such. this is just partial and not complete. click on < add new item > will add a new input box for another file upload
<form action="{{request.path}}" method="post" enctype="multipart/form-data" id="upload_form">
{%csrf_token%}
<input type="text" name="name" id="name" value="{{request.POST.name}}"/>
<input type="text" name="categorie" id="categorie" value="{{request.POST.categorie}}"/>
<div class="file_inputs" id="file_inputs">
<input type="file" name="docfile" id="id_docfile">
</div>
<input type="submit" value="Upload">
</form>
@bofh19
bofh19 / base_site.html
Created July 17, 2013 15:15
using tinyMCE on all textarea fields in django. put this in your django_app/admin/base_site.html
{% extends "admin/base.html" %}
{% load i18n %}
{% block title %}{{ title }} | {% trans 'SOME TITLE' %}{% endblock %}
{% block branding %}
<h1 id="site-name">{% trans 'SOME TITLE' %}</h1>
{% endblock %}
{% block extrahead %}
<style type="text/css">
@bofh19
bofh19 / client_java.java
Last active December 19, 2015 20:09
Android to Django POST securely using hmac algorithm described here http://www.thebuzzmedia.com/designing-a-secure-rest-api-without-oauth-authentication/
// http://stackoverflow.com/questions/3208160/how-to-generate-an-hmac-in-java-equivalent-to-a-python-example
import org.apache.commons.codec.binary.Hex;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
public static class HashingUtility {
public static String HMAC_MD5_encode(String key, String message) throws Exception {
SecretKeySpec keySpec = new SecretKeySpec(
key.getBytes(),
"HmacMD5");
@bofh19
bofh19 / python_snippets.py
Created July 16, 2013 13:30
few python snips
#generate random string X is lenght of it
import random,string
''.join(random.sample(string.ascii_lowercase+string.ascii_uppercase+string.digits, X))
# check only for particular set of strings exists or not.
import re
reg = re.compile('^[a-zA-Z0-9_]+$')
string = "SomeString___"
string_fail = "SomeString..3+__)"
reg.match(string) # <- returns a match
@bofh19
bofh19 / youtubedata.js
Created July 15, 2013 15:09
getting youtube video data using api
//youtube url https://www.youtube.com/watch?v=id <- video_id is this one.
//for thumbnail images use this url
//http://img.youtube.com/vi/{{video_id}}/0.jpg
//0.jpg is always hd thumbnail image .. 1.jpg, 2.jpg 3.jpg is for thumbnail 1,2,3
function getYouTubeInfo(video_id) {
$.ajax({
url: "http://gdata.youtube.com/feeds/api/videos/"+video_id+"?v=2&alt=json",
dataType: "jsonp",
success: function (data) {
@bofh19
bofh19 / CacheManager.java
Last active December 19, 2015 09:39
Android Url Cache Manager. get data from url < caches them if requested with same url next time >
package com.w4rlock.cacheManager;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.MappedByteBuffer;
@bofh19
bofh19 / template.html
Created July 5, 2013 11:59
upload multiple files from url's into django image field
<form action="{{request.path}}" method="post" enctype="multipart/form-data" id="upload_form">
{%csrf_token%}
<div class="text_inputs" id="text_inputs">
<input type="text" name="doctext" id="id_doctext">
</div>
<input type="submit" value="Upload">
</form>
<a href="#" onClick="addformelement()" >add new item</a>
<script type="text/javascript">
@bofh19
bofh19 / django_move_data_to_slave.py
Created June 28, 2013 20:36
Django move your data to slave from default
# don't remember from where i got this
from django.contrib.contenttypes.models import ContentType
def run():
def do(Table):
if Table is not None:
table_objects = Table.objects.all()
for i in table_objects:
i.save(using='slave')
package com.emil.android.util;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.telephony.TelephonyManager;
/**
* Check device's network connectivity and speed
* @author emil http://stackoverflow.com/users/220710/emil