Skip to content

Instantly share code, notes, and snippets.

@nikhil3000
nikhil3000 / webServer.java
Created June 9, 2025 18:58
A simple java webserver using sockets api
// server.java
package org.example;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;
public class Server {
@Path("/data")
@Produces(MediaType.APPLICATION_JSON)
public class Route {
MyDAO dao;
public Route(Jdbi jdbi) {
dao = jdbi.onDemand(MyDAO.class);
try {
dao.testQuery();
} catch (Exception e) {
dao.createUserTable();
public class User {
private int id;
private String name;
public User() {}
public User(int _id, String _name) {
this.id = _id;
this.name = _name;
}
public interface MyDAO {
@SqlUpdate("create table userData (id int primary key, name varchar(100))")
void createUserTable();
@SqlUpdate("insert into userData (id, name) values (:id, :name)")
void insert(@Bind("id") int id, @Bind("name") String name);
@SqlQuery("select name from userData where id = :id")
String findNameById(@Bind("id") int id);
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-jdbi3</artifactId>
<version>${dropwizard.version}</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.11</version>
</dependency>
@Valid
@NotNull
private DataSourceFactory database = new DataSourceFactory();
@JsonProperty("database")
public void setDataSourceFactory(DataSourceFactory factory) {
this.database = factory;
}
@JsonProperty("database")
database:
# the name of your JDBC driver
driverClass: org.postgresql.Driver
# the username
user: <username>
# the password
password: <passowrd>
@Path("/getData")
@Produces(MediaType.APPLICATION_JSON)
public class Route {
@GET
public String getData() {
String s = "Hello world";
return s;
}
a83350f9af7058f0e3134a0f1beeb4b7b1ab997942afee13c4ebbfb87346a2c9485aba3fb48b12df463a951cec77ba119363b32332f5f7c9194e4249e975a600
@nikhil3000
nikhil3000 / renameFiles.js
Created December 24, 2018 19:20
Nodejs code to remove some special characters and numbers from the names of files in a folder
var fs = require('fs');
fs.readdir('./data',(err,items)=>{
// console.log(items);
items.map(file=>{
let newFile = file.replace(/\d+/g,'');
newFile = newFile.replace(/-/g,' ');
newFile = newFile.replace(/_/g,' ');
fs.rename('./data/'+file, './data/'+newFile, (err)=>{
if(err)