Skip to content

Instantly share code, notes, and snippets.

View team172011's full-sized avatar
🎯
Focusing

Simon team172011

🎯
Focusing
View GitHub Profile
@team172011
team172011 / curl.md
Created April 2, 2023 12:51 — forked from subfuzion/curl.md
curl POST examples

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.

@team172011
team172011 / regexCheatsheet.js
Created November 5, 2022 22:03 — forked from sarthology/regexCheatsheet.js
A regex cheatsheet 👩🏻‍💻 (by Catherine)
let regex;
/* matching a specific string */
regex = /hello/; // looks for the string between the forward slashes (case-sensitive)... matches "hello", "hello123", "123hello123", "123hello"; doesn't match for "hell0", "Hello"
regex = /hello/i; // looks for the string between the forward slashes (case-insensitive)... matches "hello", "HelLo", "123HelLO"
regex = /hello/g; // looks for multiple occurrences of string between the forward slashes...
/* wildcards */
regex = /h.llo/; // the "." matches any one character other than a new line character... matches "hello", "hallo" but not "h\nllo"
regex = /h.*llo/; // the "*" matches any character(s) zero or more times... matches "hello", "heeeeeello", "hllo", "hwarwareallo"
@team172011
team172011 / XMLAdapter.java
Last active March 24, 2022 09:02
XmlAdapter for String to XML
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
@team172011
team172011 / ZonedDateTimeToUtilDate.java
Last active September 5, 2020 10:07
java.time.ZonedDateTime to java.util.Date
java.time.ZonedDateTime myZonedDateTime = java.time.ZonedDateTime.now();
java.util.Date date = java.util.Date.from(myZonedDateTime.toInstant());
@team172011
team172011 / FileUploadSpring.java
Created November 29, 2019 15:38
Fileupload with Spring
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@PostMapping(value= "/projects/{name}/upload", consumes = { "multipart/form-data" })
ResponseEntity<String> addConfigurationAsXml(@PathVariable String name, @RequestPart("file") MultipartFile upfile){
byte[] bytes = upfile.getBytes();
return new ResponseEntity<>("Done..", HttpStatus.OK)
}
@team172011
team172011 / FileUploadJersey.java
Created November 29, 2019 15:30
FileUpload with Jersey/Javax
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.StreamingOutput;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.StreamingOutput;
@POST
@Path(value = "/fileUpload")
@team172011
team172011 / createZipAsByteArray.java
Created October 17, 2019 15:55
Create a zip file with several entries
private byte[] createZipAsByteArray(Path path, Map<String, File> files) throws IOException {
String pathToZip = path.toString()+File.separator+"content.zip";
FileOutputStream fileOutputStream = new FileOutputStream(pathToZip);
ZipOutputStream zipOutputStream = new ZipOutputStream(fileOutputStream);
byte[] buffer = new byte[1024];
int len;
for(Map.Entry<String, File> file: files.entrySet()) {
FileInputStream fileInputStream2 = new FileInputStream(file.getValue());
ZipEntry zipEntry = new ZipEntry(file.getKey());
zipOutputStream.putNextEntry(zipEntry);
@team172011
team172011 / unzipToParentDir.java
Created October 17, 2019 15:53
Unzip a zip file with all zip entries in java
private void unzipToParentDir(File file) throws IOException {
try (ZipFile zipFile = new ZipFile(file)) {
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
File entryDestination = new File(file.getParent(), entry.getName());
if (entry.isDirectory()) {
entryDestination.mkdirs();
} else {
entryDestination.getParentFile().mkdirs();
@team172011
team172011 / deleteDirRecursive.java
Created October 17, 2019 15:52
Delete a folder in java
public static void deleteDirRecursive(File folder) {
File[] files = folder.listFiles();
if (files != null) {
for (File f : files) {
if (f.isDirectory()) {
deleteDirRecursive(f);
} else {
f.delete();
}
}
@team172011
team172011 / InputStreamToString.java
Last active June 24, 2019 07:27
Write the content of a file (InputStream) to an String variable
public static String getFileContent(FileInputStream fis, String encoding ) throws IOException{
try(BufferedReader br =new BufferedReader(new InputStreamReader(fis, encoding))){
StringBuilder sb = new StringBuilder();
String line;
while(( line = br.readLine()) != null ) {
sb.append( line );
sb.append( '\n' );
}
return sb.toString();
}