Skip to content

Instantly share code, notes, and snippets.

View TheGreatJoules's full-sized avatar
Working from home

Julian Carachure TheGreatJoules

Working from home
  • 02:30 (UTC -07:00)
View GitHub Profile
@TheGreatJoules
TheGreatJoules / ArrayToList.java
Last active August 5, 2023 07:43
[Java/ArrayToList] ArrayToList using streams #streams #java
int[] example = new int[] {1, 2, 3};
Arrays.stream(example)
.boxed()
.collect(Collectors.toList());
# Edit and add fan threshold
sudo vim /etc/udev/rules.d/70-snap.snapd.rules
# Update and reload
sudo udevadm control --reload-rules && udevadm trigger
#Reboot
sudo reboot
# Install sensors
// You can use an initializer in an anonymous subclass to make the syntax a little bit shorter:
Map<String, String> myMap = new HashMap<String, String>() {{
put("a", "b");
put("c", "d");
}};
// In plain java 8 you also have the possibility of using Streams/Collectors to do the job.
Map<String, String> myMap = Stream.of(
new SimpleEntry<>("key1", "value1"),
@TheGreatJoules
TheGreatJoules / BackupLinuxImage.sh
Last active August 5, 2023 07:44
[Bash/Backup] backup the entire linux system to image
# backup linux image
# DSK='disk4' # manual set disk
OUTDIR=./$1/snapshots/
mkdir -p OUTDIR
# Find disk with Linux partition
## Note: This also works with Raspbian
export DSK=`diskutil list | awk '/Linux/ {print $5}' | cut -c 1-5 | uniq`
if [ $DSK ]; then
echo $DSK
echo $OUTDIR
@TheGreatJoules
TheGreatJoules / RestoreLinuxImage.sh
Last active August 5, 2023 07:44
[Bash/RestoreLinux] Restore system to the latest linux iso #bash
#!/bin/bash
# restore backup
DSK='disk3'
# Image name (no ext)
IMG='latest'
# Check for sensible disk
export PTYPE=$(diskutil list /dev/$DSK | awk '/GUID_partition_scheme/ {print $2}; /Apple/ {print $2}; /Windows_NTFS/ {print $2}' )
@TheGreatJoules
TheGreatJoules / comments.sh
Created June 19, 2022 01:08
Bash Mutli Line Comments
<<'###BLOCK-COMMENT'
line 1
line 2
line 3
line 4
###BLOCK-COMMENT
@TheGreatJoules
TheGreatJoules / DeepAndShallowCopy.java
Last active August 5, 2023 23:40
[Java/Copy] A simple code explanation of the representation of shallow and deep copy arrays. #java #copy
/**
* ShallowCopy
*/
int[] a = new int[] {1,2,3};
int[] b = new int[a.length];
b = Arrays.copyOf(a, a.length);
/**
* DeepCopy
*/
@TheGreatJoules
TheGreatJoules / StreamCharArray.java
Last active August 5, 2023 07:44
[Java/CharToArray]An approach to stream char array
char[] result = {'a','b','c'};
String output = Stream.of(result)
.map(String::valueOf)
.collect(Collectors.joining())
@TheGreatJoules
TheGreatJoules / SimpleCronTab.sh
Last active August 12, 2023 21:37
[Bash/Crontab] Simple crontab scheduler to run code snippet
30 6 * * * cd ~/devo/message && ./script.sh
@TheGreatJoules
TheGreatJoules / Leetcode_438_Solution_A.java
Last active October 22, 2023 08:01
[Leetcode/438] Find All Anagrams in a String #slidingwindow
class Solution {
public List<Integer> findAnagrams(String s, String p) {
List<Integer> result = new ArrayList<>();
if (s == null || s.length() == 0) {
return result;
}
if (p == null || p.length() > s.length()) {
return result;
}
int[] s_freq = new int[26];