Skip to content

Instantly share code, notes, and snippets.

@hilfritz
hilfritz / Python Stuff
Created December 5, 2021 13:42
Python Stuff
#PYTHON FILTER String LIST VIA LAMBDA
list = ["Main.py", "util.py", "Test.py", "Main.java", "Util.java", "Test.java"]
#GET ALL FILES ENDING WITH .py
allpythonfiles = filter(lambda x: x.endswith(".py"), allfiles)
#GET ALL FILES ENDING WITH .java
allpythonfiles = filter(lambda x: x.endswith(".java"), allfiles)
@hilfritz
hilfritz / Linux commands
Last active February 8, 2022 04:23
Linux commands
find . -name "*textToSearch*" -print
find . -iname "*textToSearch*" -print (case insensitive)
--recursive search for a file in directory that contains 'textToSearch' in file name
find . -maxdepth 1 -name "*textToSearch*" -print
-- -maxdepth 1 - means search only in current directory, not subdirectories
-- https://stackoverflow.com/questions/11328988/find-all-files-with-name-containing-string
find libdir -name "*.jar" -exec zipgrep "TEXTTOFINDINSIDEJAR" '{}' \;
find . -name "*.jar" -exec zipgrep "TEXTTOFINDINSIDEJAR" '{}' \;
Loading image with updates
- takes more process/memory than regular image loading in flutter
- advantage: sure that the image is updated properly
1. load image from /data/picture1.jpg (1001 bytes)
2. replace image but retain same name /data/picture1.png (850 bytes)
* normal loading will not update the image, using the below code the change in image gets reflected
ClipRRect(
borderRadius: BorderRadius.circular(16.0),
child: Image.memory(
Uint8List.fromList(
@hilfritz
hilfritz / RXDart
Last active October 10, 2019 04:37
Dart Flutter
/*
* Prints the items in the list with delay
*/
StreamSubscription<String> timerSubscription;
List<String> iterable = ["2", "1", "x"];
timerSubscription = Observable.fromIterable(timerText).concatMap((i) {
return new Observable.timer(i, Duration(seconds: 1));
}).listen((x) {
print(x); //Prints "2" , 1 sec later then prints "1", 1 sec later prints "x"
if (x == iterable[0]) {
@hilfritz
hilfritz / gist:af0f54bc8a38503a1626ad60946a4ec1
Last active October 31, 2022 08:46
EditTextViewUtil - util to make edittext look like textview
import android.content.Context
import android.graphics.drawable.Drawable
import android.graphics.drawable.ShapeDrawable
import android.graphics.drawable.shapes.RectShape
import android.support.v4.content.ContextCompat
import android.support.v4.widget.NestedScrollView
import android.text.method.ScrollingMovementMethod
import android.view.Gravity
@hilfritz
hilfritz / gist:18776d94d4c6d113c30cde9ed4a04f10
Created December 7, 2018 09:02
Android: Rxjava RxAndroid Countdown timer
//source: https://github.com/ReactiveX/RxJava/issues/3505
####Emit each item 5 seconds after the previous item:
List<Integer> list = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5, 6));
Observable
.interval(5, TimeUnit.SECONDS)
.map(i -> list.get(i.intValue()))
.take(list.size())
.toBlocking()
.subscribe(System.out::println)
@hilfritz
hilfritz / gist:f4650863968427e08df9c734e76892c7
Created December 5, 2018 05:57
android: changing dialogfragment width & height
DialogFragmentClass{
@Override
public void onStart() {
super.onStart();
int width = (int)(getResources().getDisplayMetrics().widthPixels*0.95);
int height = (int)(getResources().getDisplayMetrics().heightPixels*0.30);
getDialog().getWindow().setLayout(width, ViewGroup.LayoutParams.WRAP_CONTENT);
//THIS WILL MAKE WIDTH 90% OF SCREEN
//HEIGHT WILL BE WRAP_CONTENT
//getDialog().getWindow().setLayout(width, height);
@hilfritz
hilfritz / gist:5a8ca9e172918bc224f03c3dac9c39f3
Last active June 2, 2022 03:38
Android OnClickListener Prevent multiple clicks
import android.view.View;
/**
* inspired and credits
* @see http://stackoverflow.com/questions/16534369/avoid-button-multiple-rapid-clicks
* A Debounced OnClickListener
* Rejects clicks that are too close together in time.
* This class is safe to use as an OnClickListener for multiple views, and will debounce each one separately.
* This class allows a single click and prevents multiple clicks on
* the same button in rapid succession. Setting unclickable is not enough
@hilfritz
hilfritz / gist:1f6ec5833bae1a47106622fc598b0625
Created November 13, 2018 10:28
Android similar width/height in all device dimentions
//see https://stackoverflow.com/questions/37067271/android-graphics-drawing-same-size-circles
float devicePixelsWidth = fragment.getResources().getDisplayMetrics().widthPixels;
float deviceActualDpi = fragment.getResources().getDisplayMetrics().xdpi ;
float deviceActualInchWidth = devicePixelsWidth / deviceActualDpi ;
float deviceActualCMWidth = deviceActualInchWidth * 2.54f ;
float PixelsForActual3CM = devicePixelsWidth / deviceActualCMWidth * 3;
float radius = (float) (devicePixelsWidth / deviceActualCMWidth * 0.05);
@hilfritz
hilfritz / IOS study
Last active November 19, 2018 12:35
IOS study
//----------------------------------SHORTCUTS----------------------
AUTORESIZE LABEL ACCORDING TO TEXT
- SELECT LABEL + press CMD + '='
STRING CONCAT
//let passwordInput = "HI THERE"
//let usernameInput = "HELLO THERE
let passwordInput:String = passwordField.text ?? ""
let usernameInput:String = userNameField.text ?? ""
let age = 19