Skip to content

Instantly share code, notes, and snippets.

View pkozelka's full-sized avatar

Petr Kozelka pkozelka

View GitHub Profile
@pkozelka
pkozelka / rm-trailing-ws.sh
Created September 24, 2023 12:04
Remove trailing whitespaces
#!/bin/bash
find * -name '*.java' | xargs sed -i 's:^\(.*[^[:space:]]\)[[:space:]]*$:\1:;'
@pkozelka
pkozelka / both_mixed_async.rs
Last active February 7, 2024 17:49
Process execution in Rust
use std::path::Path;
use std::process::Stdio;
use tokio::io::BufReader;
use tokio::io::AsyncBufReadExt;
use tokio::process::Command;
use tokio::sync::mpsc;
/// Execute a process, gather its mixed outputs into stdout
///
@pkozelka
pkozelka / todos.md
Last active April 4, 2021 20:27
Notes for RUST warp, the todos example
@pkozelka
pkozelka / rename-idate.sh
Created December 29, 2020 04:52
prefix filename with file's date
#!/bin/bash
# Indicated files will be renamed by prefixing with their modification date.
# Useful for photos from old devices that did not store metadata.
# This only prints the `mv` commands (preview); pipe it to `sh` to apply the changes
function filetime() {
local f=$1
local t=$(stat -c %y "$f")
t=${t%% *}
@pkozelka
pkozelka / keybase.md
Created March 15, 2016 22:16
keybase.md

Keybase proof

I hereby claim:

  • I am pkozelka on github.
  • I am pkozelka (https://keybase.io/pkozelka) on keybase.
  • I have a public key whose fingerprint is 66B4 1E80 692D C42E 37D6 E37C B79E B1A1 5EB7 0771

To claim this, I am signing this object:

@pkozelka
pkozelka / http-redir-bash-server.md
Created September 18, 2014 20:17
Simple Redirecting Webserver in a bash script
@pkozelka
pkozelka / DateToIso.java
Created September 20, 2011 11:56
convert Date into ISO-formatted string
class DateToIso {
/**
* This uses java formatter for the conversion
*/
public String toString(Date date) {
return String.format("%tFT%<tT.%<tL", date);
}
}
@pkozelka
pkozelka / git-config.markdown
Created June 7, 2011 08:40
My favorite GIT configuration

.git/config

git config --global user.name 'Petr Kozelka'
git config --global user.email 'petr.kozelka@hp.com'
git config --global color.ui auto
git config --global log.date iso8601

git config --global alias.st 'status --porcelain'

git config --global core.excludesfile ~/src/pkozelka-admin/gitexcludes

@pkozelka
pkozelka / ProcessUploadRequest.java
Created December 22, 2010 11:02
Processing upload requests with commons-upload
///... somewhere in the servlet, called from doPost:
private void processUploadRequest(HttpServletRequest request, PrintWriter pw) throws FileUploadException, IOException {
final FileItemFactory factory = new DiskFileItemFactory();
final ServletFileUpload upload = new ServletFileUpload(factory);
@SuppressWarnings("unchecked")
final List<FileItem> items = upload.parseRequest(request);
log("LIST: " + items);
for (FileItem item : items) {
final String fieldName = item.getFieldName();
if (item.isFormField()) {