Skip to content

Instantly share code, notes, and snippets.

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

Buddha Man Nepali bmnepali

🏠
Working from home
View GitHub Profile
@bmnepali
bmnepali / semantic-layout.html
Created July 2, 2019 09:35 — forked from thomd/semantic-layout.html
Standard HTML5 Semantic Layout
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Title</title>
<link href="stylesheets/main.css" rel="stylesheet" />
</head>
<body>
<header>
<hgroup>
@bmnepali
bmnepali / enzyme_render_diffs.md
Created July 3, 2019 05:45 — forked from fokusferit/enzyme_render_diffs.md
Difference between Shallow, Mount and render of Enzyme

Shallow

Real unit test (isolation, no children render)

Simple shallow

Calls:

  • constructor
  • render
@bmnepali
bmnepali / axios-catch-error.js
Created July 28, 2019 10:18 — forked from fgilio/axios-catch-error.js
Catch request errors with Axios
/*
* Handling Errors using async/await
* Has to be used inside an async function
*/
try {
const response = await axios.get('https://your.site/api/v1/bla/ble/bli');
// Success 🎉
console.log(response);
} catch (error) {
// Error 😨
@bmnepali
bmnepali / node-encrypt-decrypt.js
Created January 29, 2020 10:29
Node Js Crypto encrypt and decrypt methods for secure data encryption.
'use strict';
const crypto = require('crypto');
const ENCRYPTION_KEY = process.env.ENCRYPTION_KEY; // Must be 256 bits (32 characters)
const IV_LENGTH = 16; // For AES, this is always 16
function encrypt(text) {
let iv = crypto.randomBytes(IV_LENGTH);
let cipher = crypto.createCipheriv('aes-256-cbc', Buffer.from(ENCRYPTION_KEY), iv);
@bmnepali
bmnepali / spring-boot-cheatsheet.java
Created February 12, 2020 10:39 — forked from jahe/spring-boot-cheatsheet.java
Spring Boot Cheatsheet
// Enable component-scanning and auto-configuration with @SpringBootApplication Annotation
// It combines @Configuration + @ComponentScan + @EnableAutoConfiguration
@SpringBootApplication
public class FooApplication {
public static void main(String[] args) {
// Bootstrap the application
SpringApplication.run(FooApplication.class, args);
}
}
@bmnepali
bmnepali / getDayFromDate.java
Last active March 19, 2020 12:01
Get full fay name from given date
public class GetDayFromDate {
public static void main(String[] args) {
Date now = new Date();
SimpleDateFormat simpleDateformat = new SimpleDateFormat("E"); // the day of the week abbreviated
System.out.println(simpleDateformat.format(now));
simpleDateformat = new SimpleDateFormat("EEEE"); // the day of the week spelled out completely
@bmnepali
bmnepali / TimezoneConversionExample.java
Created March 19, 2020 12:00
Convert date from one timezone to another
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
/**
*
* Java program to display a date in different timezone in Java. Internally Java
* stores date as millisecond passed since 01-01-1970 00:00 GMT, which can be
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
public class HelloWorld{
public static void main(String []args){
System.out.println("Hello World");
LocalTime time = LocalTime.parse("10:00:00"); // 10 AM
public static Date localToGMT() {
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
Date gmt = new Date(sdf.format(date));
return gmt;
}
public static Date gmttoLocalDate(Date date) {
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.Calendar;
import java.util.Date;