Skip to content

Instantly share code, notes, and snippets.

Avatar

Milos MilosSimic

  • Faculty of technical sciences Novi Sad
  • Novi Sad
View GitHub Profile
@MilosSimic
MilosSimic / NetworkHelper.java
Created Jun 1, 2020 — forked from alphamu/NetworkHelper.java
Gist showing the use case of a headless Fragment to check if internet is available
View NetworkHelper.java
public class NetworkHelper extends Fragment {
public static final String TAG = "NetworkHelper";
public static final String CHECK_INTERNET = "network_connection";
private Activity mActivity;
AlertDialog mAlertDialog = null;
private BroadcastReceiver onNotice = new BroadcastReceiver() {
@Override
@MilosSimic
MilosSimic / MyImageView.java
Created Mar 24, 2020 — forked from naufraghi/MyImageView.java
Move and zoom image with Gestures in and android View
View MyImageView.java
package com.develer.circularsliderule;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.View;
@MilosSimic
MilosSimic / install_go_pi.sh
Created Dec 25, 2019 — forked from pcgeek86/install_go_pi.sh
Install Go Lang on Raspberry Pi
View install_go_pi.sh
cd $HOME
FileName='go1.13.4.linux-armv6l.tar.gz'
wget https://dl.google.com/go/$FileName
sudo tar -C /usr/local -xvf $FileName
cat >> ~/.bashrc << 'EOF'
export GOPATH=$HOME/go
export PATH=/usr/local/go/bin:$PATH:$GOPATH/bin
EOF
source ~/.bashrc
@MilosSimic
MilosSimic / ctx_middleware_chain.go
Created Nov 26, 2019 — forked from cep21/ctx_middleware_chain.go
Example of using context.Value() as a middleware chain
View ctx_middleware_chain.go
package goexperiments
import (
"context"
"net/http"
)
type HandlerMiddleware interface {
HandleHTTPC(ctx context.Context, rw http.ResponseWriter, req *http.Request, next http.Handler)
}
@MilosSimic
MilosSimic / 1_http_hello.go
Created Nov 22, 2019 — forked from jmervine/1_http_hello.go
Golang - Hello PATH HTTP Server Example
View 1_http_hello.go
package main
import (
"fmt"
"log"
"net/http"
)
func Log(handler http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@MilosSimic
MilosSimic / timeout_and_tick.go
Created Oct 26, 2019 — forked from ngauthier/timeout_and_tick.go
Golang timeout and tick loop
View timeout_and_tick.go
// keepDoingSomething will keep trying to doSomething() until either
// we get a result from doSomething() or the timeout expires
func keepDoingSomething() (bool, error) {
timeout := time.After(5 * time.Second)
tick := time.Tick(500 * time.Millisecond)
// Keep trying until we're timed out or got a result or got an error
for {
select {
// Got a timeout! fail with a timeout error
case <-timeout:
@MilosSimic
MilosSimic / assetlinks.json
Created Oct 18, 2019 — forked from adewale/assetlinks.json
Example assetlinks.json
View assetlinks.json
@MilosSimic
MilosSimic / EncodeBased64Binary.java
Created May 14, 2019 — forked from utsengar/EncodeBased64Binary.java
Encode a file to base64 binary in Java
View EncodeBased64Binary.java
import org.apache.commons.codec.binary.Base64;
private String encodeFileToBase64Binary(String fileName)
throws IOException {
File file = new File(fileName);
byte[] bytes = loadFile(file);
byte[] encoded = Base64.encodeBase64(bytes);
String encodedString = new String(encoded);
@MilosSimic
MilosSimic / gist:8c223973e90220c4e05d3bb860b2d3fb
Created May 14, 2019 — forked from nickrussler/gist:7527851
Convert Date String to/from ISO 8601 respecting UTC in Java
View gist:8c223973e90220c4e05d3bb860b2d3fb
public static String toISO8601UTC(Date date) {
TimeZone tz = TimeZone.getTimeZone("UTC");
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'");
df.setTimeZone(tz);
return df.format(date);
}
public static Date fromISO8601UTC(String dateStr) {
TimeZone tz = TimeZone.getTimeZone("UTC");
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'");
You can’t perform that action at this time.