Skip to content

Instantly share code, notes, and snippets.

@ssinganamalla
ssinganamalla / LoadProperties.java
Created January 12, 2016 23:15
Load config properties file located in resources directory
public static ApplicationProperties loadProperties() {
Properties prop = new Properties();
InputStream input = null;
try {
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
input = classloader.getResourceAsStream("config.properties");
// load a properties file
prop.load(input);
@ssinganamalla
ssinganamalla / renamedb.sql
Created August 27, 2015 01:39
rename database name in postgres
//delete the user sessions
SELECT pg_terminate_backend( pid )
FROM pg_stat_activity
WHERE pid <> pg_backend_pid( )
AND datname = 'oldname';
ALTER DATABASE oldname RENAME TO newname
@ssinganamalla
ssinganamalla / ProgramSingle.java
Last active August 29, 2015 14:20
Single Dispatch
public class Program
{
/**
yes thats me
yes thats me
you will have to use Double Dispatch in order for u to print 2 statements
**/
public static void main(String[] args)
@ssinganamalla
ssinganamalla / LinkedListIntersection.java
Last active October 9, 2015 12:39
Intersection of two linkedlists
/*Write a program to find the node at which the intersection of two singly linked lists begins.
For example, the following two linked lists:
A: a1 → a2
c1 → c2 → c3
B: b1 → b2 → b3
@ssinganamalla
ssinganamalla / MaxNumber.java
Last active October 10, 2015 23:41
LargestNumber
/*
Given a list of non negative integers, arrange them such that they form the largest number.
For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330.
Note: The result may be very large, so you need to return a string instead of an integer.
*/
public class MaxNumber {
String getLargestNumber(List<Integer> numbers) {
@ssinganamalla
ssinganamalla / Node.java
Last active August 29, 2015 14:14
Given a BST and a node (say target), find K nearest neighbors. http://www.geeksforgeeks.org/print-nodes-distance-k-given-node-binary-tree/
package com.mycompany.tree;
public class Node {
public int value;
public Node left;
public Node right;
public int level;
public Node(int value) {
@ssinganamalla
ssinganamalla / JpaUserRepositoryImpl.java
Created August 16, 2013 00:19
find the single record.
public User findByEmail(String email) {
Query query = this.em.createQuery("SELECT user FROM User u where u.email= :theemail");
query.setParameter("theemail", email);
return (User) query.getSingleResult();
}
@*Empty div otherwise the deployment is not successful. keep the hack, till u figure out*@
<div></div>
@{
ViewBag.Title = "AFE Administration";
}
<!DOCTYPE html>
<html>
<head>
<title>@ViewBag.Title</title>
<link href="@Url.Content("../../Scripts/resources/AfeAdmin-all.css")" rel="stylesheet" type="text/css" />
<!-- TO GO IN DEV MODE: comment the line -->
<!-- <script src="@Url.Content("../../Scripts/all-classes.js")" type="text/javascript"></script>-->
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>AfeAdmin</title>
<!-- <x-compile> -->
<!-- <x-bootstrap> -->
<link rel="stylesheet" href="bootstrap.css">
<script src="ext/ext-dev.js"></script>
<script src="bootstrap.js"></script>