Skip to content

Instantly share code, notes, and snippets.

View robinraju's full-sized avatar

Robin Raju robinraju

View GitHub Profile
@robinraju
robinraju / ValidDate.java
Created June 15, 2016 07:19
Java Annotation for validating Date format in the given string
import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
/**
@robinraju
robinraju / ValidCurrencyCode.java
Created June 15, 2016 07:22
Java Annotation for validating ISO country code in the given string
import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
@robinraju
robinraju / Error.java
Last active June 15, 2016 07:35
JAX-RS Exception mapper for returning http response messages from Hibernate Validator or any other bean validator
package com.mycompany.error;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
@Data
public class Error {
@JsonProperty(value = "errorMessage")
private String errorMessage;
@robinraju
robinraju / mysql-upsert.sql
Last active August 2, 2016 09:18
MySQL Upsert | Update row if exists, otherwise perform Insert
INSERT INTO <TABLE>
(<COLUMN 1>, <COLUMN 2>)
VALUES( <VALUE 1>,<VALUE 2>)
ON DUPLICATE KEY UPDATE
`<COLUMN1>` = '<VALUE1>';
@robinraju
robinraju / csvToJson.html
Created August 4, 2016 12:11
Convert CSV document to JSON, using jquery
<!DOCTYPE html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-alpha1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-csv/0.71/jquery.csv-0.71.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
// The event listener for the file upload
document.getElementById('txtFileUpload').addEventListener('change', upload, false);
@robinraju
robinraju / ConnectionUtil.java
Created August 4, 2016 12:20
Ignoring SSL certificate – javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
public class ConnectionUtil {
public static void trustConnection(){
$ df
This will list all mounted devices
$ sudo umount /dev/sdc<?>
where <?> is a number, look it up. Then, next:
$ sudo dd bs=4M if=input.iso of=/dev/sdc<?>
where input.iso is the input file, and /dev/sdc<?> is the USB device you're writing to.
@robinraju
robinraju / angular-connectivity-detection.ts
Last active July 26, 2018 17:14
Detecting internet connectivity status inside angular application
import {Component, OnDestroy, OnInit} from '@angular/core';
import {fromEvent, Observable, Subscription} from 'rxjs';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit, OnDestroy {
onlineEvent: Observable<Event>;
@robinraju
robinraju / .htaccess
Created October 10, 2018 09:34 — forked from jacobovidal/.htaccess
Upgrade Insecure Requests via .htaccess or meta tag to prevent mixed content
<ifModule mod_headers.c>
Header always set Content-Security-Policy "upgrade-insecure-requests;"
</IfModule>
@robinraju
robinraju / PrevNext.scala
Created February 20, 2020 16:05
SCALA: Find the previous and next elements of an item in a list
def getPrevAndNext[A](lst: List[A], el: A): Option[(Option[A], A, Option[A])] = {
lst match {
case Nil => None
case x :: Nil if x == el => Some(None, x, None)
case _ :: Nil => None
case x :: y :: Nil if x == el => Some(None, x, Some(y))
case x :: y :: Nil if y == el => Some(Some(x), y, None)
case x :: y :: z :: zs if x == el => Some(None, x, Some(y))
case x :: y :: z :: zs if y == el => Some(Some(x), y, Some(z))
case _ => getPrevAndNext(lst.tail, el)