Skip to content

Instantly share code, notes, and snippets.

View alshell7's full-sized avatar

Owais alshell7

View GitHub Profile
@alshell7
alshell7 / async_task.md
Last active June 17, 2016 19:46
Androids AsyncTask Explanation

##Basically AsyncTask uses generic types in its parameters The three types used by an asynchronous task are the following:

  • Params, the type of the parameters sent to the task upon execution.
  • Progress, the type of the progress units published during the background computation.
  • Result, the type of the result of the background computation.

Not all types are always used by an asynchronous task. To mark a type as unused, simply use the type Void: private class MyTask extends AsyncTask<Void, Void, Void> { ... }

##Taking a very known and common example..

@hbcafe
hbcafe / gist:a16f0546fe56f687d9da994593b55a92
Created October 18, 2016 17:58
Connect native Android app to Watson Sentiment Analysis in under 10 minutes
package com.ibm.sentimentsensitiveapp;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
@xalexchen
xalexchen / KeyframeAnimation.java
Created September 17, 2013 05:44
This example shows how to use AnimationDrawable to construct a keyframe animation where each frame is shown for a specified duration.
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
@sureshdsk
sureshdsk / facebook-graph-api-page.py
Last active March 25, 2019 15:23
Get number of likes of a facebook page using graph api in python
# http://www.idiotinside.com/2015/02/13/get-number-of-likes-of-a-facebook-page-using-graph-api-in-python/
import urllib2
import json
def get_page_data(page_id,access_token):
api_endpoint = "https://graph.facebook.com/v2.4/"
fb_graph_url = api_endpoint+page_id+"?fields=id,name,likes,link&access_token="+access_token
try:
api_request = urllib2.Request(fb_graph_url)
@fbchow
fbchow / gist:5815dac910b725dfa2b0af0e0ad6dd2a
Last active April 28, 2019 08:55
Copying & Moving Files
I always forget the exacty syntax for copying & moving files, especially when dealing with a remote Linux server. And I had wrote some documentation years ago but lost it (so much for persistent storage!). So here's some notes:
Change into the directory you want to download the files
cd /home/dir_to_dump_file_in
Log onto server using Safe File Transfer Protocol--just like how you would "ssh" into the Linux server
sftp homersimpson@sprinfielduniversity.edu
password: ilovemarge
Obtain the files from the Linux server on to your local server
# Create first network with Keras
from keras.models import Sequential
from keras.layers import Dense
import numpy
import threading as t
import tensorflow as tf
graph = tf.get_default_graph()
def t_thread():
@dusenberrymw
dusenberrymw / tensorflow_tips_and_tricks.md
Last active April 2, 2020 16:49
Tips and tricks for TensorFlow, Keras, CUDA, etc.

TensorFlow Tips & Tricks

GPU Memory Issues

  • nvidia-smi to check for current memory usage.
  • watch -n 1 nvidia-smi to monitor memory usage every second.
  • Often, extra Python processes can stay running in the background, maintaining a hold on the GPU memory, even if nvidia-smi doesn't show it.
    • Probably due to running Keras in a notebook, and then running the cell that starts the processes again, since this will fork the current process, which has a hold on GPU memory. In the future, restart the kernel first, and stop all process before exiting (even though they are daemons and should stop automatically when the parent process ends).
@bamthomas
bamthomas / pub_sub_redis.py
Created November 28, 2012 22:16
Pub/Sub redis python
from multiprocessing.process import Process
import time
import redis
def pub(myredis):
for n in range(10):
myredis.publish('channel','blah %d' % n)
time.sleep(5)
def sub(myredis, name):
"""Easily save tf.data.Datasets as tfrecord files, and restore tfrecords as Datasets.
The goal of this module is to create a SIMPLE api to tfrecords that can be used without
learning all of the underlying mechanics.
Users only need to deal with 2 functions:
save(dataset)
dataset = load(tfrecord, header)
To make this work, we create a .header file for each tfrecord which encodes metadata
import android.graphics.Bitmap;
/**
* Created by paveld on 3/6/14.
*/
public class FastBlur {
public static Bitmap doBlur(Bitmap sentBitmap, int radius, boolean canReuseInBitmap) {
// Stack Blur v1.0 from