Skip to content

Instantly share code, notes, and snippets.

@jbaranski
jbaranski / LiquibaseCompositePrimaryKey.md
Created August 1, 2020 14:43
Liquibase Composite Primary Key

Here are two examples of how to define a composite primary key for some table using Liquibase.

  • Add the composite primary key up front during table construction (preferred).
  <changeSet id="1">
    <createTable tableName="some_table">
      <column name="id_1" type="varchar_ignorecase">
        <constraints nullable="false" primaryKey="true" primaryKeyName="PK_SOME_TABLE"></constraints>
 
@jbaranski
jbaranski / oracledb.py
Created September 4, 2016 20:01
Python Oracle DB connection wrapper
"""
Oracle database connection wrapper
@author: jbaranski
"""
import cx_Oracle
class OracleDB:
"""
Usage:
@jbaranski
jbaranski / NodeJSLocalModule.md
Created August 1, 2020 14:49
Node.js local module

The following package.json snippet is how to reference a local module in your Node.js project:

package.json

{
  ...
  "dependencies": {
    "local-module": "file:./local-module",
    ...
 }
@jbaranski
jbaranski / ReadYamlAndJson.md
Created August 1, 2020 14:48
Read in YAML or JSON file using Python

The following code will read in a YAML file and store it in a dictionary. The dictionary content is then printed to the console.

config.yaml

test: value
nested:
  test: nestedValue

@jbaranski
jbaranski / SSHSpecificPrivateKey.md
Created August 1, 2020 14:44
SSH Use Specific Private Key

If you have multiple SSH keys generated for different purposes (one for GitHub, one for server administration, etc...) you can specify which private key to use via config.

In ~/.ssh/config you may have the following:

host github.com
 HostName github.com
 IdentityFile ~/.ssh/id_rsa.github
 User <your PC user name (not GitHub user name)>
@jbaranski
jbaranski / DisableCSRFOAuth2SpringBoot.md
Created August 1, 2020 14:42
Disable CSRF while using OAuth 2 in Spring Boot

Many examples on the internet just say to call http.csrf().disable(), but this ends up disabling all authentication (causes the AuthenticationPrincipal to always be null).

Here is how to disable CSRF protection for a REST service when using Spring Boot without disabling all authentication.

@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
    @Override
 protected void configure(HttpSecurity http) throws Exception {
@jbaranski
jbaranski / SingleJarDownload.md
Created August 1, 2020 14:41
Download a Single Dependency with Maven
@jbaranski
jbaranski / AddH2UserPass.md
Created August 1, 2020 14:40
Add User and Password to Existing H2 Database

I needed to password protect an existing H2 database. I wanted to do two things:

  • Delete existing ADMIN user, who had no user name or password:

DROP USER "";

  • Create a new user, add a password for the new user:

CREATE USER IF NOT EXISTS example PASSWORD 'example password' ADMIN;

@jbaranski
jbaranski / multi-table-sort-angular.ts
Last active July 12, 2020 02:26
Multi table angular sort
// assume you have a member on the component like dataSource1: MatTableDataSource<any>; and dataSource2: MatTableDataSource<any>; that
// are the datasources for the two tables
@ViewChildren(MatSort) set matSort(matSortList: QueryList<MatSort>) {
const ref = this;
matSortList.forEach((matSort: any, index: number) => {
const dataSource = ref['dataSource' + (index + 1)];
// https://material.angular.io/components/table/api
// to see about sortingDataAccessor
dataSource.sortingDataAccessor = (item: any, property: string) => {
if (cond1) {
@jbaranski
jbaranski / Trie.js
Last active February 11, 2020 03:39 — forked from tpae/Trie.js
Trie.js - super simple JavaScript implementation
/* tslint:disable */
import { AutocompleteCandidate } from '../autocomplete/candidate';
// Source code token from below link
// https://gist.github.com/tpae/72e1c54471e88b689f85ad2b3940a8f0
// @MODIFIED has been added where modifications have been made
//
// Trie.js - super simple JS implementation
// https://en.wikipedia.org/wiki/Trie