Skip to content

Instantly share code, notes, and snippets.

View jsfan3's full-sized avatar
💡
I make mobile apps using Codename One + Spring Boot

Francesco Galgani jsfan3

💡
I make mobile apps using Codename One + Spring Boot
View GitHub Profile
@jsfan3
jsfan3 / AppApplication.java
Created June 3, 2019 06:58
Cloudinary in Spring Boot - Three files: the main AppApplication, the Controller and the Service, by Francesco Galgani, www.informatica-libera.net
package yourpackage.app;
import com.cloudinary.Cloudinary;
import com.cloudinary.SingletonManager;
import com.cloudinary.utils.ObjectUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
@jsfan3
jsfan3 / countIP.sh
Created January 23, 2023 07:43
Counts IPv4 addresses in MaxMind's GeoLite2 database
#!/bin/bash
### Counts IPv4 addresses in MaxMind's GeoLite2 database ###
### It does the summation of how many IPs are in each CIDR range ###
### https://dev.maxmind.com/geoip/geolite2-free-geolocation-data ###
echo "Warning: the execution of this script can take many hours!"
param=0 # $param contains the summation
skip='true' # we use $skip to skip the first row, containing the CSV header row
@jsfan3
jsfan3 / TabsSwipeTest.java
Created November 22, 2021 10:44
Codename One - Test Tabs swipe on X-Axis and Y-Axis
Form hi = new Form("Test swipe on tabs", BorderLayout.absolute());
Tabs tabs = new Tabs();
ButtonGroup btnGroup = new ButtonGroup();
Button swipeXBtn = RadioButton.createToggle("Swipe on X-Axis", btnGroup);
Button swipeYBtn = RadioButton.createToggle("Swipe on Y-Axis", btnGroup);
btnGroup.setSelected(0);
swipeXBtn.addActionListener(l -> {
tabs.setSwipeOnXAxis(true);
});
@jsfan3
jsfan3 / AppSettingsUtilitiesImpl.java
Created January 2, 2019 23:47
Codename One Android Native Interface to access the app settings
package net.informaticalibera.cn1.simpleapi;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.provider.Settings;
public class AppSettingsUtilitiesImpl {
private static Context context() {
@jsfan3
jsfan3 / CaptureAndPlaybackAudioSample
Last active August 13, 2021 14:44
Demonstrates capturing of audio files and their playback using the Codename One APIs Media, MediaManager and MediaRecorderBuilder
private static final EasyThread countTime = EasyThread.start("countTime");
public void start() {
if (current != null) {
current.show();
return;
}
Form hi = new Form("Recording audio", BoxLayout.y());
hi.add(new SpanLabel("Example of recording and playback audio using the Media, MediaManager and MediaRecorderBuilder APIs"));
hi.add(recordAudio((String filePath) -> {
@jsfan3
jsfan3 / conteggio.sh
Created July 3, 2020 14:58
Conteggio codice
#!/bin/bash
DIR=~/Projects
cd $DIR
# Contare classi:
a=`find . -name \*.java -print | wc -l`
echo ""
echo "Number of Java classes: $a"
# Conteggio complessivo:
@jsfan3
jsfan3 / Example.java
Created June 28, 2020 16:51
Spring Boot: URL to JSON. This solution solves 403 and 1010 errors
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
[...]
@jsfan3
jsfan3 / Example.java
Created June 27, 2020 14:43
UIID Generation Example
Form hi = new Form("Test UIID", BoxLayout.y());
Button button = new Button("Generate 10 UIID");
hi.add(button);
hi.show();
button.addActionListener(l -> {
String myId = "myUsername"; // do not exceed 12 characters
Preferences.set("CustomDeviceId__$", Long.parseLong(myId, 36));
hi.add(new SpanLabel("10 Random UUID"));
for (int i = 0; i < 10; i++) {
hi.add(new SpanLabel(Util.getUIID()));
@jsfan3
jsfan3 / MyApplication.java
Last active June 2, 2020 22:53
Codename One Util.downloadUrlSafely example
import com.codename1.components.SpanLabel;
import com.codename1.components.ToastBar;
import static com.codename1.ui.CN.*;
import com.codename1.ui.Display;
import com.codename1.ui.Form;
import com.codename1.ui.Dialog;
import com.codename1.ui.Label;
import com.codename1.ui.plaf.UIManager;
import com.codename1.ui.util.Resources;
import com.codename1.io.Log;
@jsfan3
jsfan3 / RunnableWithArg.java
Created May 8, 2019 12:59
Java Runnable With Arg
public interface RunnableWithArg<T> {
/**
* Similar to the runnable interface but it accepts an argument
*
* @param arg any type of argument
*/
public void run(T arg);
}