Skip to content

Instantly share code, notes, and snippets.

@bofh19
bofh19 / index.html
Last active November 1, 2017 21:09
A CodePen by bofh19. analyser - non stop and random
<canvas id="visc" width="600" height="500" style="">
Your browser does not support the canvas element.
</canvas>
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
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
@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')
@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 / 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 / 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 / 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 / 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 / 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">