Skip to content

Instantly share code, notes, and snippets.

View diamondobama's full-sized avatar
🎯
Focusing

Diamond diamondobama

🎯
Focusing
View GitHub Profile
@diamondobama
diamondobama / DoubleLeadExample.java
Last active October 18, 2020 20:37
Add 2 actions to a single container, one action on the entire container and the other on a specific button.
// Create the bottom container and add all components except the close button
Button lead = new Button("");
lead.addActionListener(evt -> System.out.println("Other parts of the container clicked!"));
Label centerLabel = new Label("This is a test label...");
Label westIcon = new Label(myIcon);
Container bottom = BorderLayout.centerEastWest(centerLabel, null, westIcon);
bottom.setLeadComponent(lead);
// Position the close button at the right location
Button closeButton = new Button("Close");
@diamondobama
diamondobama / StringUtils.java
Last active August 15, 2022 16:49
String helper methods to perform various string manipulations in Codename One.
package group.diamonddev.util;
import com.codename1.io.Util;
import com.codename1.l10n.L10NManager;
import com.codename1.util.StringUtil;
import com.codename1.util.regex.RE;
import java.util.*;
/**
@diamondobama
diamondobama / ParseInputStream.php
Created April 3, 2019 07:52 — forked from devmycloud/ParseInputStream.php
Process php://input to get multipart/form-data parameters for PATCH API request
<?php
use Illuminate\Support\Facades\Log;
use Symfony\Component\HttpFoundation\File\UploadedFile;
/**
* stream - Handle raw input stream
*
* LICENSE: This source file is subject to version 3.01 of the GPL license
* that is available through the world-wide-web at the following URI:
<?php
namespace App;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
@diamondobama
diamondobama / PseudoCrypt.php
Last active January 24, 2017 00:34 — forked from ethanpil/gist:94455f8de76671aa9024
PseudoCrypt.php
<?php
/**
* Reference/source: http://stackoverflow.com/a/1464155/933782
*
* I want a short alphanumeric hash that’s unique and who’s sequence is difficult to deduce.
* I could run it out to md5 and trim the first n chars but that’s not going to be very unique.
* Storing a truncated checksum in a unique field means that the frequency of collisions will increase
* geometrically as the number of unique keys for a base 62 encoded integer approaches 62^n.
* I’d rather do it right than code myself a timebomb. So I came up with this.
*
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.codename1.test;
import com.codename1.contacts.Contact;
import com.codename1.contacts.ContactsManager;
import com.codename1.ui.Button;
@diamondobama
diamondobama / Sample.java
Created January 16, 2016 08:27 — forked from shannah/Sample.java
A background painter that puts a circle in the background of a component.
BackgroundPainter p = new BackgroundPainter(cmp) {
@Override
public void paint(Graphics g, Rectangle rect) {
boolean antiAliased = g.isAntiAliased();
g.setAntiAliased(true);
int r = Math.min(rect.getWidth(), rect.getHeight())/2;
int x = rect.getX() + rect.getWidth()/2 - r;
int y = rect.getY() + rect.getHeight()/2 - r;
switch (style) {
@diamondobama
diamondobama / BGLocationTest.java
Created January 16, 2016 08:26 — forked from shannah/BGLocationTest.java
Geofence Example
package com.codename1.tests.bglocation;
import com.codename1.location.Geofence;
import com.codename1.location.Location;
import com.codename1.location.LocationManager;
import com.codename1.ui.Display;
import com.codename1.ui.Form;
import com.codename1.ui.Label;
import com.codename1.ui.plaf.UIManager;
package com.codename1.tests.bglocation;
import com.codename1.location.Geofence;
import com.codename1.location.Location;
import com.codename1.location.LocationManager;
import com.codename1.ui.Display;
import com.codename1.ui.Form;
import com.codename1.ui.Label;
import com.codename1.ui.plaf.UIManager;