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 / 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 / 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 / sendCode.sh
Created May 9, 2020 11:51
Modify, compile and upload the local Netbeans Spring Boot project to the destination testing VPS, installing it as a Linux service
#!/bin/bash
# REMEMBER TO REPLACE THE FOLLOWING VALUES
YOUR_TESTING_SERVER="mydomain.net"
SERVERCODE_DIR="MyServer"
SERVERCODE_DIR_PATH="/home/francesco/NetBeansProjects/"
JAR="MyServer-1.0.0-SNAPSHOT.jar"
SERVERCODE_FULLPATH=$SERVERCODE_DIR_PATH$SERVERCODE_DIR
echo "Server code full path: $SERVERCODE_FULLPATH"
@jsfan3
jsfan3 / CodeExample.java
Last active May 7, 2020 09:48
Codename One Image.exifRotation usage example
Form hi = new Form("Hi World", BoxLayout.y());
Button cameraBtn = new Button("Open Camera");
Button galleryBtn = new Button("Open Gallery");
Label imageLbl = new Label();
hi.addAll(cameraBtn, galleryBtn, FlowLayout.encloseCenter(imageLbl));
hi.show();
SuccessCallback<String> callback = (String capturedPhoto) -> {
String rotatedPhoto = FileSystemStorage.getInstance().getAppHomePath() + "rotatedPhoto.jpg";
if (capturedPhoto != null) {
@jsfan3
jsfan3 / MyApplication.java
Last active May 4, 2020 15:02
Codename One fast image scaling algorithm to generate thumbnails from captured photos. This optimization makes sense on Android and Simulator (Java SE) only. See: https://github.com/codenameone/CodenameOne/issues/3090
package net.informaticalibera.test.imagescaling;
import com.codename1.capture.Capture;
import com.codename1.components.SpanLabel;
import com.codename1.io.FileSystemStorage;
import static com.codename1.ui.CN.*;
import com.codename1.ui.Form;
import com.codename1.ui.Dialog;
import com.codename1.ui.Label;
import com.codename1.ui.plaf.UIManager;
@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) -> {