Skip to content

Instantly share code, notes, and snippets.

@Marchuck
Marchuck / Loop.java
Created August 3, 2015 20:06
how to invoke the same method in a loop
public class Loop {
private static boolean isStarted = false;
private static Handler handler = new Handler();
private static ConcreteActivity activity;
public static boolean isActive = true;
private static Runnable stepTimer = new Runnable() {
@Override
@Marchuck
Marchuck / Splitter.java
Created August 8, 2015 15:02
Get query value used with observables response.getUrl() extracter
String getQuery(String url, String field){
String[] divider = url.split(field+"=");
String[] spliter = divider[1].split("&");
return spliter[0];
}
package pl.sointeractive.smartcity.service;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.support.annotation.NonNull;
import android.support.design.widget.Snackbar;
import android.util.Log;
import android.view.View;
@Marchuck
Marchuck / pizza_stores.cpp
Created August 26, 2015 16:27
pizza stores
[{"id":2060,"name":"Pizza Dracula","street":"Turystyczna","number":"2","plz":"31-213","telephone":"124312668","email":"[email protected]","locationName":"Kraków","locationId":9454,"stateId":6,"status":0,"isOnline":1,"isnew":false,"paymentbar":1,"preorder":"day","url":"pizza-dracula-krakow","onlycash":0,"specialComment":"Polaczenie uszkodzone, przlaczam na dyktowane","imageUrl":"https://image.yourdelivery.de/pyszne.pl/service/2060/Pizza+Dracula-0-0.jpg","ratingCount":1199,"ratingAdviceCount":1137,"ratingAverage":4.62,"tags":"Dania rybne, Dania z grilla, Pizza","openings":[{"from":"10:00","until":"22:30","day":0},{"from":"10:00","until":"22:30","day":1},{"from":"10:00","until":"22:30","day":2},{"from":"10:00","until":"22:30","day":3},{"from":"10:00","until":"22:30","day":4},{"from":"10:00","until":"22:30","day":5},{"from":"10:00","until":"22:30","day":6}],"openingSpecial":{},"mealTypes":null,"restaurantCategory":"Włoska","franchiseTypeId":1,"franchiseType":"normal","holidays":null,"sms":true,"favouriteCoun
@Marchuck
Marchuck / marquee.java
Last active September 4, 2015 06:44
horyzontalna markiza MarqueeTextView needs textView.setSelected(true) at onBindViewHolder()
<TextView
android:id="@+id/draggable_list_swipe_item_stops_stop_name_data"
android:layout_width="100sp"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/fragment_timetable_padding"
android:layout_marginTop="@dimen/fragment_text_margin"
android:text="@string/draggable_list_item_stops_stop_name"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#e0000000"
android:singleLine="true"
@Marchuck
Marchuck / compiles.c
Last active September 26, 2015 10:49
gradle essentials
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:recyclerview-v7:22.2.1'
compile 'com.android.support:support-annotations:23.0.1'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'io.reactivex:rxandroid:0.25.0'
compile 'io.reactivex:rxjava:1.0.10'
compile 'io.reactivex:rxjava-math:0.21.0'
@Marchuck
Marchuck / HashCodeUniversal.java
Created October 4, 2015 11:01
Effective Java snippets
@Override
public int hashCode(){
int result = 17;
result = 31 * result + someBoolean ? 1:0;
result = 31 * result + someByte;
result = 31 * result + someChar;
result = 31 * result + someShort;
result = 31 * result + someInt;
result = 31 * result + someLong ^ someLong >>> 32 ;
result = 31 * result + Float.floatToIntBits(someFloat);
@Marchuck
Marchuck / Deserializer.java
Created October 4, 2015 11:38
Generic deserializers with Retrofit & rxJava
public abstract class Deserializer<T> implements JsonDeserializer<T> {
public abstract Class<T> setDestinationClass();
@Override
public T deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
Log.d("Deserializer", "deserialize json: " + json);
return new Gson().fromJson(json, setDestinationClass());
}
@Marchuck
Marchuck / Request.java
Created October 13, 2015 19:56
Request
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
public class Request{
public void post(String data){