Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

var fs = require("fs")
fs.createReadStream("apache-camel-build.md")
.pipe(markdownpdf())
.pipe(fs.createWriteStream("apache-camel-build.pdf"))
var markdownpdf = require("markdown-pdf")
markdownpdf().from("apache-camel-build.md").to("apache-camel-build.pdf", function () {
console.log("Done")
})
@peterkeller
peterkeller / script.sh
Last active July 9, 2021 09:28
GIT Tagging
# list tags
git tag
# search tag
git tag -l "1.0.*"
# add lightweight tag
git tag "1.0.0"
# delete local tag '1.0.0'
git tag -d 1.0.0
# delete remote tag '1.0.0'
git push --delete origin 1.0.0
@peterkeller
peterkeller / drop_tables_in_ms_sql_server.sql
Last active June 17, 2021 08:05
Drop all tables in MS SQL Server
-- https://www.mssqltips.com/sqlservertip/6798/drop-all-tables-sql-server/
USE [BikeStores]
GO
-- drop constraints
DECLARE @DropConstraints NVARCHAR(max) = ''
SELECT @DropConstraints += 'ALTER TABLE ' + QUOTENAME(OBJECT_SCHEMA_NAME(parent_object_id)) + '.'
+ QUOTENAME(OBJECT_NAME(parent_object_id)) + ' ' + 'DROP CONSTRAINT' + QUOTENAME(name)
FROM sys.foreign_keys
EXECUTE sp_executesql @DropConstraints;
@peterkeller
peterkeller / StdoutCatcher.java
Created April 24, 2021 13:11
Catches STDOUT and writes it into a string
public static String catchStdout(Runnable runnable) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
System.setOut(new PrintStream(outputStream));
runnable.run();
return outputStream.toString();
}
@Test
void testCatchStdout() {
String s = "Hello, World";
@peterkeller
peterkeller / myhandle.component.ts
Last active April 24, 2021 08:08
RxJS operator to handle errors
// https://stackoverflow.com/questions/52797992/which-rxjs-operator-to-choose-to-handle-http-errors-tap-or-catcherror/61836193#61836193
// "tap" is to cause side effects and it doesn't modify the chain at all, "catchError" is to catch errors in a stream and try to handle them.
http.get('https://test.com/').pipe(
tap(
() => {
// 200, awesome!, no errors will trigger it.
},
(error: HttpErrorResponse) => {
// error is here, but we can only call side things.
},
@peterkeller
peterkeller / PersonSpecification.java
Created December 7, 2020 12:30
JPA CriteriaBuilder with Sub-String Matching
// Take sub-string before first space ' ' if there is any or else take the whole string
private static Expression<String> nameSplit(
Root<Person> root,
CriteriaBuilder builder,
SingularAttribute<Person, String> str
) {
Expression<Integer> indexStart = builder.literal(1);
Expression<Integer> indexOfFirstSpace = builder.locate(root.get(str), " ");
Expression<Integer> stringLength = builder.length(root.get(str));
// if indexOfFirstSpace = 0, then no space ' ' is found
@peterkeller
peterkeller / script.sh
Created August 30, 2020 19:49
Happy Birthday
echo "Stream.of(0b01001000,0b01100001,0b01110000,0b01110000,0b01111001,0b00100000,0b01000010,0b01101001,0b01110010,0b01110100,0b01101000,0b01100100,0b01100001,0b01111001).map(Character::toChars).forEach(System.out::print)" | jshell -
@peterkeller
peterkeller / script.sh
Last active July 14, 2020 06:11
Compile and run TypeScript in a shell
echo "console.log('Hello, World')" > index.ts
tsc index.ts
node index.js
# Standard error is redirected to standard output, so both are redirected to debug.log
perl test.pl > debug.log 2>&1
# Standard output goes to out.log, and standard error to err.log
perl test.pl 1>out.log 2>err.log