Skip to content

Instantly share code, notes, and snippets.

View sahilpaudel's full-sized avatar
🏠
Working from home

Sahil Paudel sahilpaudel

🏠
Working from home
View GitHub Profile
@sahilpaudel
sahilpaudel / ResultSet to List
Created January 25, 2022 20:06 — forked from cworks/ResultSet to List
Java - Convert a ResultSet to a List of Maps, where each Map is a row of data
/**
* Convert the ResultSet to a List of Maps, where each Map represents a row with columnNames and columValues
* @param rs
* @return
* @throws SQLException
*/
private List<Map<String, Object>> resultSetToList(ResultSet rs) throws SQLException {
ResultSetMetaData md = rs.getMetaData();
int columns = md.getColumnCount();
List<Map<String, Object>> rows = new ArrayList<Map<String, Object>>();
@sahilpaudel
sahilpaudel / app.js
Created May 27, 2020 17:56
Create Image from buffer and save to destination folder
const watermark = require('./watermark');
const path = `assets/target.png`;
const w = 500;
const h = 500;
watermark.drawWatermarkAsBuffer(path, './assets/watermark_source.png', w, h).then(buffer => {
require("fs").writeFile("assets/output.png", buffer, 'base64', function(err) {
console.log(err);
});
});
@sahilpaudel
sahilpaudel / watermark.js
Created May 27, 2020 16:41
Watermark Using Canvas
const { createCanvas, loadImage } = require('canvas');
const drawWatermarkAsBuffer = (pathOfSourceImageFile, pathOfWaterMarkImageFile, width, height) => {
const canvas = createCanvas(width, height);
const ctx = canvas.getContext('2d');
// loading the source image file
return loadImage(pathOfSourceImageFile).then(loadSourceImage => {
@sahilpaudel
sahilpaudel / Controlled_Uncontrolled_Component.js
Last active April 14, 2020 07:32
Controlled and Uncontrolled Input Component
import React from "react";
const FunctionalComponent = props => {
const [email, setEmail] = React.useState('');
const [password, setPassword] = React.useState('');
return (
<form>
<input type="email" name="email" onChange={e => setEmail(e.target.value)}/>
<input type="password" name="password" onChange={e => setPassword(e.target.value)} />
</form>
@sahilpaudel
sahilpaudel / ES6_functions.js
Last active April 14, 2020 07:21
How to create functions in JS
// Old way to create a function
function doSomething() {
console.log("Inside the old function");
}
// New ES6 way to create a function
const doSomething = () => {
console.log("Inside the new function");
}