Skip to content

Instantly share code, notes, and snippets.

@ochaloup
ochaloup / narayana tomcat integration.xml
Last active March 28, 2018 08:22
narayana tomcat integration
<Resource name="psqlDataSource" uniqueName="psqlDataSource" auth="Container"
factory="org.postgresql.xa.PGXADataSourceFactory"
type="org.postgresql.xa.PGXADataSource"
serverName="localhost"
portNumber="5432"
databaseName="test"
user="test"
password="test"
description="PostgreSQL XA Data Source"/>
@ochaloup
ochaloup / main.go
Created July 18, 2019 15:19
golang http digest to run WildFly management REST call
/*
* Using https://gowalker.org/github.com/ryanjdew/http-digest-auth-client
* for HTTP digest authentication. The request for the functionality for golang http client
* seems to be tracked at
* https://github.com/golang/go/issues/29409
*/
package main
import (
"fmt"
@ochaloup
ochaloup / sorting-with-regexp.go
Last active July 31, 2019 18:00
just testing to sort by number extracted from string with regexp
package main
import (
"fmt"
"sort"
"regexp"
"strconv"
)
type M struct {
@ochaloup
ochaloup / (child) pom.xml
Last active November 6, 2020 11:52
maven multimodule pom.xml example
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>cz.chalda</groupId>
<artifactId>chalda-parent</artifactId>
<version>1.0-SNAPSHOT</version>
@ochaloup
ochaloup / dataclass_retype.py
Created December 14, 2021 07:11
How to type dict data based on dataclass type hints?
import dataclasses
from dataclasses import dataclass
from typing import Dict, Optional
from logging import log
import typing
import inspect
## ------------ DATA -------------
@dataclass
class MyDataClass:
@ochaloup
ochaloup / dataclass_retype_2.py
Created December 15, 2021 07:44
A solution by Rob of dataclass_retype.py
from dataclasses import dataclass
from typing import Optional, Union, get_origin, get_args
@dataclass
class MyDataClass:
optional_num: Optional[int] = None
something: Union[int, str] = None
@ochaloup
ochaloup / delete_git_submodule.md
Created September 14, 2022 08:29 — forked from myusuf3/delete_git_submodule.md
How effectively delete a git submodule.

To remove a submodule you need to:

  • Delete the relevant section from the .gitmodules file.
  • Stage the .gitmodules changes git add .gitmodules
  • Delete the relevant section from .git/config.
  • Run git rm --cached path_to_submodule (no trailing slash).
  • Run rm -rf .git/modules/path_to_submodule (no trailing slash).
  • Commit git commit -m "Removed submodule "
  • Delete the now untracked submodule files rm -rf path_to_submodule
@ochaloup
ochaloup / match-either.rs
Last active November 3, 2022 13:25
How to work with two different types on match in Rust
// https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=9b5accdceb7875f4535e6bc12afbdd22
#![allow(unused)]
fn main() {
#[derive(Clone, Debug)]
struct A {
name: String,
}
#[derive(Clone, Debug)]
struct B {
@ochaloup
ochaloup / rust-trait-stuff
Last active November 15, 2022 07:55
How to work with traits and "inheritance"
// How to work with slices and how to copy item at particular place in array
// https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=e3e4d33020aa7abe15ca53ceb2d08edd
// Resources on Rust Trait
// blog: https://huonw.github.io/blog/2015/01/peeking-inside-trait-objects/
// stackoverflow1: https://stackoverflow.com/a/47966422/187035
// forum: https://users.rust-lang.org/t/extending-traits/1802/8
// stackoverflow2: https://stackoverflow.com/a/28633889/187035
#![allow(unused)]
@ochaloup
ochaloup / match + return error
Last active November 18, 2022 12:35
Simple attempt to fetch understanding on match/return of error
// https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=ceaf3827dea9f6a51fa9ecac48876652
#![allow(unused)]
fn main() {
fn say_hello(str: &str) -> Result<(), &str> {
match str {
"abc" => println!("this is abc!"),
"error" => return Err("this is error!"),
something_else => println!("{}", something_else)