Kuwait University Graduate
Research and development engineer at KGL
Computer Engineering Masters student
Background:
Interests:
Python
Web Development
Android & iOS Development
from channels import Group
from channels.sessions import channel_session
import json
from main.models import Employee
@channel_session
def connect(message):
pk = message['path'].strip('/')
Group('employee-'+ pk).add(message.reply_channel)
message.channel_session['employee'] = pk
@channel_session
def ws_receive(message):
pk = message.channel_session['employee']
data = json.loads(message['text'])
employee = Employee.objects.get(pk=pk)
employee.location.latitude = data['location']["latitude"]
employee.location.longitude = data['location']["longitude"]
employee.save()
Group('employee-' + pk).send({'text': json.dumps(data)})
@channel_session
def disconnect(message):
pk = message.channel_session['employee']
type = message.channel_session['type']
Group('employee-' + pk).discard(message.reply_channel)
function initMap() {
var myLatLng = {lat: -25.363, lng: 131.044};
var marker;
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 16,
center: myLatLng
});
marker = new google.maps.Marker({
position: myLatLng,
map: map,
title: 'Hello World!'
});
ws = new WebSocket("ws://livelocation.herokuapp.com/1");
ws.onmessage = function(event) {
var ws_location = $.parseJSON(event.data).location;
var myLatLng = {lat: ws_location.latitude, lng: ws_location.longitude};
marker.setPosition(myLatLng);
map.panTo(myLatLng);
};
ws.onclose = function() {
console.log("Socket closed");
};
ws.onopen = function() {
console.log("Connected");
};
}
Easy, right? Should take a day maximum? two?
Gonna tell you the sad truth about estimations
Couldn't find the old screenshot :(
A look at what the system scraped on its own
class ExampleActivity extends Activity {
@BindView(R2.id.user) EditText username;
@BindView(R2.id.pass) EditText password;
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.simple_activity);
ButterKnife.bind(this);
// TODO Use fields... (Yes thats it)
}
@OnClick(R.id.submit)
public void submit(View view) {
// TODO submit data to server...
}
}class ExampleActivity extends Activity {
EditText username;
EditText password;
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.simple_activity);
username=(EditText)findViewById(R.id.user);
password=(EditText)findViewById(R.id.pass);
btn=(Button)findViewById(R.id.submit);
btn.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View view) {
// Do something here
}
});
}
}// Download image
Glide.with(this)
.load("http://goo.gl/gEgYUd")
.into(imageView);
// Yes this is it
// ------ also you can load gifs -------
// Customizable
Glide.with(this)
.placeholder(R.mipmap.loading)
//can be a resource or a drawable
.error(R.drawable.sad_taco)
//fallback image if error
.fit()
// reduce the image size to dimensions
// of imageView
.resize(imgWidth, imgHeight)
//resizes the image in pixels
.centerCrop() //or .centerInside()
.rotate(90f)
//or rotate(degrees, pivotX, pivotY)
.noFade() //dont fade all fancy-like
// and more
private Bitmap DownloadImage(String url)
{
Bitmap bitmap = null;
InputStream in = null;
String TAG = "DownloadImage";
try
{
in = OpenHttpGETConnection(url);
bitmap = BitmapFactory.decodeStream(in);
in.close();
}
catch (Exception e)
{
Log.d(TAG, e.getLocalizedMessage());
}
return bitmap;
}public interface GitHubService {
@GET("users/{user}/repos")
Call<List<Repo>> listRepos(@Path("user") String user);
}
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://api.github.com/")
.build();
GitHubService service = retrofit.create(GitHubService.class);
Call<List<Repo>> repos = service.listRepos("octocat");public class Repo extends RealmObject {
@SerializedName("name") //name in JSON
private String name;
}
RealmConfiguration realmConfig =
new RealmConfiguration.Builder(context).build();
Realm.setDefaultConfiguration(realmConfig);
// Get a Realm instance for this thread
Realm realm = Realm.getDefaultInstance();
realm.beginTransaction();
// Persist unmanaged objects
final Repo repo = realm.copyToRealm(oldRepo);
// Create managed objects directly
Repo newRepo = realm.createObject(Repo.class);
realm.commitTransaction();RealmQuery<User> query = realm.where(Repo.class);
// Add query conditions:
query.equalTo("name", "octocat");
query.or().equalTo("name", "Dreamersoul");
// Execute the query:
RealmResults<User> result1 = query.findAll();
// thats it