Skip to content

Instantly share code, notes, and snippets.

View hadinajafi's full-sized avatar
🧭
Learning Android

Hadi Najafi hadinajafi

🧭
Learning Android
View GitHub Profile
@hadinajafi
hadinajafi / Gray.icls
Created February 15, 2021 13:52
Gray color scheme for Jetbrains products. Save the file & import it.
<scheme name="Gray" version="142" parent_scheme="Default">
<metaInfo>
<property name="created">2021-02-15T17:20:10</property>
<property name="ide">idea</property>
<property name="ideVersion">2020.3.1.0.0</property>
<property name="modified">2021-02-15T17:20:16</property>
<property name="originalScheme">_@user_Gray</property>
</metaInfo>
<colors>
<option name="ADDED_LINES_COLOR" value="89de73" />
@hadinajafi
hadinajafi / keybinding
Created February 14, 2021 09:57
For who purchased a UK keyboard, but they want big left shif key. replace "\" keycode with LShift, so you'll have a standard LShift. add this code to startup.
xmodmap -e "keycode 94 = Shift_L"
@hadinajafi
hadinajafi / application.properties
Created February 1, 2021 09:40
Most common spring application properties configurations
logging.level.root=info
##------------------------------------------------------
## Datasource Config
##------------------------------------------------------
spring.datasource.driver-class-name=org.postgresql.Driver
spring.jpa.properties.hibernate.id.new_generator_mappings=false
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
spring.datasource.hikari.initializationFailTimeout=15000
spring.jpa.database-platform=org
spring.datasource.url=jdbc:postgresql://localhost:5432/demo-service?useUnicode=true&characterEncoding=UTF-8
@hadinajafi
hadinajafi / ShowError
Created January 29, 2021 10:01
This shortcut code, can be assigned to anything, but I used it for showing error while pressing SHIFT+DELETE
zenity --error --text='Stop doing that!'
@hadinajafi
hadinajafi / gnome-shell.css
Last active January 11, 2021 13:58
Some Gnome shell tweaks to improve look & feel
stage {
font-size: 10.5pt;
font-weight: 400;
color: rgba(0,0,0,0.75);
}
/* add an activity icon on top of the left corner. something like apple icon, ubuntu icon, etc. */
#panel #panelActivities.panel-button > * {
background-image: url("assets/activities.svg");
background-position: center top;
@hadinajafi
hadinajafi / Streams.java
Last active December 20, 2020 17:21
Overall Java 8 Streams code samples
// break a string into multiple substrings with RegEx
Stream<String> streamOfString = Pattern.compile(", ").splitAsStream("a, b, c");
//creating stream of strings from array
String[] arr = {"a", "b", "c"};
Stream<String> streamOfArray = Arrays.stream(arr);
// every line of text becomes an element of stream
Path path = Paths.get("C:\\file.txt");
Stream<String> streamOfStrings = Files.lines(path);
@hadinajafi
hadinajafi / JtextPane.java
Created April 23, 2020 16:43
How to use Styles in Java Swing JTextPane
StyledDocument sd = (StyledDocument) jTextPane.getDocument(); //get the styled document
SimpleAttributeSet boldBlue = new SimpleAttributeSet(); //a bold, blue color, with font attribute creation
StyleConstants.setBold(boldBlue, true); //set it bold
StyleConstants.setForeground(boldBlue, Color.blue); //set the attribute color
jTextPane.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); //RTL support
StyleConstants.setFontFamily(boldBlue, "Mikhak Light"); //custom font
String text = jTextPane.getSelectedText(); //get selected text in the Editor
try {
jTextPane1.replaceSelection("");
sd.insertString(jTextPane.getCaretPosition(), text, boldBlue);
@hadinajafi
hadinajafi / NumeralJTextField.java
Created July 16, 2019 11:13
Accept only numbers for JTextfield in Swing. Pasting a string is also works for match.
//restrict the user to only input numeric format in the account field
accountID.addKeyListener(new KeyAdapter() {
@Override
public void keyTyped(KeyEvent e) {
super.keyTyped(e);
char c = e.getKeyChar();
String regex = "[0-9]*";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(String.valueOf(c));
if(!matcher.matches()){
@hadinajafi
hadinajafi / CountDownTimer.java
Created June 27, 2019 10:30
A Simple countdown timer to print time in "mm:ss" format.
int minutes = insertedValue; //init value
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
int seconds = minutes * 60;
String secString, minString; //two strings for printing
int ss = 0; //formatted second
int mm = minutes; //formatted minute
public void run(){
if(ss < 10)
secString = "0" + ss; //[0s] format: 01, 02, ... 09
@hadinajafi
hadinajafi / customfont.css
Created May 4, 2019 19:11
Addd custom font to the JavaFX application using CSS
@font-face{
font-family: Table;
src: url(gamelogger/fonts/Ubuntu-R.ttf);
}
#recentTable{
-fx-font-family: Ubuntu;
}