Skip to content

Instantly share code, notes, and snippets.

View diskostu's full-sized avatar
🤘

Denny diskostu

🤘
  • Munich, Germany
View GitHub Profile
@diskostu
diskostu / app_build.gradle.kts
Last active August 1, 2023 15:05
Update dependencies in a Android Gradle project - https://github.com/ben-manes/gradle-versions-plugin
import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
[...]
plugins {
[...]
id("com.github.ben-manes.versions")
}
configurations {
@diskostu
diskostu / WeatherMappers.kt
Last active February 10, 2023 17:34
Return the correct weatherInfo for a given LocalDataTime
https://www.youtube.com/watch?v=eAbKK7JNxCE
fun WeatherDto.toWeatherInfo(nowTime: LocalDateTime = LocalDateTime.now()): WeatherInfo {
val weatherDataMap = weatherData.toWeatherDataMap()
// the API always has weather data for a full hour, like this: "2023-02-13T13:00"
// we need to take care of the edge case: time is f.e. "23:50". Then we need the weather data for time "00:00"
// for the NEXT day
val dayIndex = if (nowTime.hour == 23 && nowTime.minute >= 30) 1 else 0
@diskostu
diskostu / mapWeatherData.kt
Last active February 10, 2023 08:04
Map weather data, first day has index 0
// https://www.youtube.com/watch?v=eAbKK7JNxCE
fun WeatherDataDto.toWeatherDataMap(): Map<Int, List<WeatherData>> {
val mapIndexed = time.mapIndexed { index, time ->
val temperature = temperatures[index]
val weatherCode = weatherCodes[index]
val windSpeed = windSpeeds[index]
val pressure = pressures[index]
val humidity = humidities[index]
@diskostu
diskostu / make_git_verbose.cmd
Created February 1, 2018 10:28
Make the git command in the console more verbose
# If you have connection issues from the local machine to GitHub, you can make the git command in the console more verbose.
# sourcee: https://stackoverflow.com/a/20492254/1057348
# Windows
set GIT_CURL_VERBOSE=1
set GIT_TRACE_PACKET=2
# Unix
# export GIT_CURL_VERBOSE=1
# export GIT_TRACE_PACKET=2
@diskostu
diskostu / MailDemo1.java
Last active July 20, 2016 09:25
Send an Email via javax.mail
package mail;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Properties;
@diskostu
diskostu / sort_map_on_values.java
Last active August 29, 2015 14:24
Sort a Map based on its values. Source: http://stackoverflow.com/a/2581754/1057348
// Java 6 and lower:
public static <K, V extends Comparable<? super V>> Map<K, V> sortByValue(Map<K, V> map) {
List<Map.Entry<K, V>> list = new LinkedList<Map.Entry<K, V>>(map.entrySet());
Collections.sort(list, new Comparator<Map.Entry<K, V>>() {
public int compare(Map.Entry<K, V> o1, Map.Entry<K, V> o2) {
return (o1.getValue()).compareTo(o2.getValue());
}
});
Map<K, V> result = new LinkedHashMap<K, V>();
@diskostu
diskostu / alternating_background.vbs
Created March 13, 2015 08:34
Set an alternating background for Excel rows based on the data in a certain column (in this example: cloumn 2 (B))
Sub Faerbe_RGB()
'Makro von PauleVBA @ gutefrage.net
Dim lngGrau As Long 'RGB-Wert fuer Grau
Dim lngWeiss As Long 'RGB-Wert für weiss
Dim lngEnde As Long 'Ende der gefuellten Zeilen
Dim lngInterneFarbe As Long 'die gewuenschte Fuellung
Dim I As Long ' einfach Zaehlvariable
lngGrau = RGB(235, 235, 235) 'Farbe Grau definieren
lngWeiss = RGB(255, 255, 255) 'Farbe weiss definieren
// These two need to be declared outside the try/catch
// so that they can be closed in the finally block.
HttpURLConnection urlConnection = null;
BufferedReader reader = null;
// Will contain the raw JSON response as a string.
String forecastJsonStr = null;
try {
// Construct the URL for the OpenWeatherMap query
@diskostu
diskostu / setWidgetWidth.java
Created November 13, 2013 12:51
Wenn man die Breite für ein Widget (secondWidget) manuell anhand der Breite eines anderen Widgets (firstWidget) setzen will, kann man dies erst dann tun, nachdem das erste Widget gerendert wurde.
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand()
{
public void execute()
{
int offsetWidth = firstWidget.getOffsetWidth();
secondWidget.setWidth(offsetWidth + "px");
}
});