Skip to content

Instantly share code, notes, and snippets.

@sairamkrish
sairamkrish / pg-copy-streams-helper.js
Last active March 8, 2021 01:10
Javascript bulk insert into postgresql using pg-copy-streams. The code is explained here - https://medium.com/@sairamkrish/how-to-do-postgresql-bulk-insert-with-node-pg-copy-streams-f4301ec29388
/*
Pseudo code - to serve as a help guide.
*/
const copyFrom = require('pg-copy-streams').from;
const Readable = require('stream').Readable;
const { Pool,Client } = require('pg');
const fs = require('fs');
const path = require('path');
const datasourcesConfigFilePath = path.join(__dirname,'..','..','server','datasources.json');
const datasources = JSON.parse(fs.readFileSync(datasourcesConfigFilePath, 'utf8'));
@sairamkrish
sairamkrish / Timer.js
Last active January 27, 2019 03:30
Simple countdown timer with ReactJs with callback support. This can be plugged into any ReactJS ecosystem like Redux, Flux. This also provides localStorage support to restore when browser crashes. Code explanation is provided here - https://medium.com/@sairamkrish/reactjs-countdown-timer-with-support-for-callbacks-browsercrash-and-optimal-render…
import React, {Component} from 'react';
import './Timer.scss'; //Have your own styling
import { Row, Col } from 'reactstrap';
export class Timer extends Component {
constructor(props){
super(props);
this.state = {
remainingMinutes: 0,
remainingSeconds: 0
@sairamkrish
sairamkrish / App.js
Last active August 18, 2023 04:45
Integrate eventEmitter with react-notification-system
/*
Base component to hold the Notification.
We don't need to have Notification in every single React component.
*/
class App extends PureComponent {
render () {
return (
<div>
…….
@sairamkrish
sairamkrish / choice.csv
Last active March 16, 2018 10:28
which JDK to choose
Schenario JDK Choice Reason
Bundling JDK with your product OpenJDK OpenJDK is licensed under GNU GPLv2. Oracle is licensed under Oracle Binary Code License Agreement
Using JDK during development OracleJDK Oracle comes with additional features for debugging
@sairamkrish
sairamkrish / Dockerfile
Last active January 4, 2022 23:27
Dockerfile for gradle, spring boot application using multi-stage feature
FROM openjdk:8 AS TEMP_BUILD_IMAGE
ENV APP_HOME=/usr/app/
WORKDIR $APP_HOME
COPY build.gradle settings.gradle gradlew $APP_HOME
COPY gradle $APP_HOME/gradle
RUN ./gradlew build || return 0
COPY . .
RUN ./gradlew build
FROM openjdk:8
@sairamkrish
sairamkrish / build.gradle
Last active May 22, 2018 12:49
Sample gradle build
buildscript {
ext {
springBootVersion = '2.0.2.RELEASE'
}
repositories {
mavenCentral()
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
docker volume create --name gradle-cache
docker run --rm -v gradle-cache:/home/gradle/.gradle -v "$PWD":/home/gradle/project -w /home/gradle/project gradle:4.7.0-jdk8-alpine gradle build
ls -ltrh ./build/libs
FROM openjdk:8
ENV APP_HOME=/usr/app/
WORKDIR $APP_HOME
COPY ./build/libs/* ./app.jar
EXPOSE 8080
CMD ["java","-jar","app.jar"]
version: '3.3'
services:
mongo:
image: mongo:3.6
restart: always
hostname: mongo
ports:
- '27017:27017'
volumes:
@sairamkrish
sairamkrish / angular.json
Created May 30, 2018 12:38
AngularPlayground with ng-bootstrap
{
...
"playground": {
"root": "",
"sourceRoot": "src",
"projectType": "application",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",