Skip to content

Instantly share code, notes, and snippets.

@rhamedy
rhamedy / README.md
Last active January 30, 2021 23:34
Save the file that is uploaded via Resumable.js in Express App

I created this gist from here https://github.com/23/resumable.js in order to modify the node.js sample for the purpose of allowing the uploaded file to be saved locally.

Instructions on how to see the answer to the following question http://stackoverflow.com/questions/33288192/resumable-js-cant-save-file-to-server-side-directory

  1. Create a directory (i.e. resumable-app)
  2. copy/paste the app.js (atleast), resumable.js and resumable-node.js from gist in the directory (you can copy the resumable.js and resumable-node.js from official github if you want too, not change has been made to them)
  3. copy/paste the package.json and do a npm install to get the modules (or manually npm install these express, path, fs, connect-multiparty)
  4. create uploads directory in the main app directory and make sure it is writable
@rhamedy
rhamedy / fileUploadsWithBusboy.js
Last active June 19, 2024 08:02
Upload files with busboy module nodejs and expressjs
//you do not necessary need all of the following, i copy/pasted a piece from
//one of my projects.
var express = require('express');
var fs = require('fs');
var Busboy = require('busboy');
var mime = require('mime');
var https = require('https');
var querystring = require('querystring');
var router = express.Router();
@rhamedy
rhamedy / README.md
Last active June 1, 2022 02:20
Configure HikariCP with Spring Boot JPA Hibernate and PostgreSQL as a database

I came across HikariCP and I was amazed by the benchmarks and I wanted to try it instead of my default choice C3P0 and to my surprise I struggled to get the configurations right probably because the configurations differ based on what combination of tech stack you are using.

I have setup Spring Boot project with JPA, Web, Security starters (Using [Spring Initializer][1]) to use PostgreSQL as a database with HikariCP as connection pooling.
I have used Gradle as build tool and I would like to share what worked for me for the following assumptions:

  1. Spring Boot Starter JPA (Web & Security - optional)
  2. Gradle build tool
  3. PostgreSQL running and setup with a database (i.e. schema, user, db)

This gist is related to SO post https://stackoverflow.com/questions/26490967/how-do-i-configure-hikaricp-in-my-spring-boot-app-in-my-application-properties-f

@rhamedy
rhamedy / Student Test Plan.jmx
Created July 13, 2019 21:12
Apache JMeter List And Create Student Endpoints
<?xml version="1.0" encoding="UTF-8"?>
<jmeterTestPlan version="1.2" properties="5.0" jmeter="5.1.1 r1855137">
<hashTree>
<TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Student Test Plan" enabled="true">
<stringProp name="TestPlan.comments"></stringProp>
<boolProp name="TestPlan.functional_mode">false</boolProp>
<boolProp name="TestPlan.tearDown_on_shutdown">true</boolProp>
<boolProp name="TestPlan.serialize_threadgroups">false</boolProp>
<elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
<collectionProp name="Arguments.arguments"/>
@rhamedy
rhamedy / Student CRUD Load Test.jmx
Created July 13, 2019 21:28
A sample Apache JMeter Load Test that performs CRUD operations on Student object
<?xml version="1.0" encoding="UTF-8"?>
<jmeterTestPlan version="1.2" properties="5.0" jmeter="5.1.1 r1855137">
<hashTree>
<TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Student CRUD Load Test Demo" enabled="true">
<stringProp name="TestPlan.comments"></stringProp>
<boolProp name="TestPlan.functional_mode">false</boolProp>
<boolProp name="TestPlan.tearDown_on_shutdown">true</boolProp>
<boolProp name="TestPlan.serialize_threadgroups">false</boolProp>
<elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
<collectionProp name="Arguments.arguments"/>
@rhamedy
rhamedy / TestEncodingDecoding
Created June 11, 2020 02:20
Test encoding and decoding outputs of com.sun.jersey.core.util.Base64 with java.util.Base64
import static org.junit.Assert.*;
import com.sun.jersey.core.util.Base64;
import org.junit.Test;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class TestEncodingDecoding {
@rhamedy
rhamedy / BrokenPipeException
Created June 12, 2020 03:55
Run the following code snippet in multiple by calling a somewhat slow endpoint and if you comment out line 19-23 then you will observe IOException:Broken pipe
private static void makeGetCall(URL url) throws IOException {
//make connection
HttpURLConnection myURLConnection = (HttpURLConnection) url.openConnection();
myURLConnection.setRequestProperty("Authorization", "token/whatever");
myURLConnection.setRequestMethod("GET");
myURLConnection.setRequestProperty("Content-Type", "application/json");
myURLConnection.setRequestProperty("User-Agent", "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)");
myURLConnection.setRequestProperty("Content-Language", "en-US");
myURLConnection.setUseCaches(false);
myURLConnection.setDoInput(true);
@rhamedy
rhamedy / pom.xml
Last active July 5, 2020 19:37
Java Spring Boot with JaCoCo test coverage pom.xml
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
@rhamedy
rhamedy / build.gradle
Created July 6, 2020 00:35
Java Spring Boot with JaCoCo Code Coverage with Gradle
plugins {
id 'org.springframework.boot' version '2.3.1.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
id 'eclipse'
id 'jacoco'
}
group = 'codecov.article'
version = '0.0.1-SNAPSHOT'
@rhamedy
rhamedy / Utility.java
Created September 24, 2020 01:05
A sample utility class with a few methods for testing
package com.diffblue.demo;
import org.springframework.util.Assert;
/**
* The following methods are used to automatically generate unit test for.
*/
public class Utility {
enum Color {
RED,