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 / 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
@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 / 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 / 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 / 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 / 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 / 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 / api.js
Created March 9, 2019 05:07
Redirect to login on 401 in react using axios
import axios from 'axios';
import Config from './app.config';
const instance = axios.create({
baseURL: Config.apiPath,
});
/**
* Catch the AunAuthorized Request
*/
@bmnepali
bmnepali / replaceStringInFile.js
Created March 6, 2019 11:07
Replace desired string in the file using the nodejs
var fs = require('fs')
fs.readFile(someFile, 'utf8', function (err,data) {
if (err) {
return console.log(err);
}
var result = data.replace(/string to be replaced/g, 'replacement');
fs.writeFile(someFile, result, 'utf8', function (err) {
if (err) return console.log(err);
});
@bmnepali
bmnepali / The Technical Interview Cheat Sheet.md
Created February 20, 2019 11:13 — forked from tsiege/The Technical Interview Cheat Sheet.md
This is my technical interview cheat sheet. Feel free to fork it or do whatever you want with it. PLEASE let me know if there are any errors or if anything crucial is missing. I will add more links soon.

Studying for a Tech Interview Sucks, so Here's a Cheat Sheet to Help

This list is meant to be a both a quick guide and reference for further research into these topics. It's basically a summary of that comp sci course you never took or forgot about, so there's no way it can cover everything in depth. It also will be available as a gist on Github for everyone to edit and add to.

Data Structure Basics

###Array ####Definition:

  • Stores data elements based on an sequential, most commonly 0 based, index.
  • Based on tuples from set theory.