Skip to content

Instantly share code, notes, and snippets.

View nishant8BITS's full-sized avatar
🎯
Focusing

Nishant Kumar nishant8BITS

🎯
Focusing
View GitHub Profile
function translateError(msg) {
var newErr = new Error(msg); // placed here to get correct stack
return e => {
newErr.originalError = e;
throw newErr;
}
}
async function asyncTask() {
const user = await UserModel.findById(1).catch(translateError('No user found'))
<script type="text/javascript">
var _dcq = _dcq || [];
var _dcs = _dcs || {};
</script>
@nishant8BITS
nishant8BITS / cover-letter.md
Created January 28, 2018 11:07 — forked from ivoputzer/cover-letter.md
cover letter

Cover Letter

My name is Ivo and I am an Italian agile software developer who loves coding and solving problems in a simple yet creative fashion. During my years of web development I have grown a strong passion for fronted development which led me to a good understanding of its underlaying technologies. I love hacking the hell out of web apps and getting a grasp of cutting edge technologies in order to keep up with time and deliver the best user experience possible.

While user experience still plays a big role in what I enjoy doing, I've learnt how important it is to write stable yet maintainable and scalable backend solutions. Even though I started out with PHP, I soon naturally came closer to the NodeJS environment while still embracing more "elegant" technologies such as Ruby or Java either adopting frameworks or by implementing architectures from scratch.

I discovered the Agile Manifesto and eXtreme Programming back while joining XPeppers in 2013 and I’ve tried my best to apply either values and prin

// From callback to async/await
// 1. Callback
const makeHttpRequest = (url, methodType, callback) => {
const xhr = XMLHttpRequest();
xhr.open(methodType, url, true);
xhr.onreadystatechange = () =>{
if(xhr.readyState === 4 && xhr.status === 200){
// Function Component
// Well, as you know, function components are a little limited.
// All they know about is their current props. They can’t access previous props or external state.
// And they’re only re-rendered when their parent is; they can’t be re-rendered individually.
//
// class components give you the power to store state, communicate with the outside world,
// and re-render whenever you’d like. But class components can be simple, too! In fact,
// any function component can also be implemented as a class component.
//
@nishant8BITS
nishant8BITS / ArrayFlatten.js
Created January 13, 2018 06:02
Flatten javascript Array into a single-depth Array Raw
function flattenArray(array){
const toFlatterArray = [];
if(Array.isArray(array)){
array.map((elm)=>{
if(Array.isArray(elm)){
const arrayList = flattenArray(elm);
arrayList.map((_elm)=>{
toFlatterArray.push(_elm);
});
}else{
//Q1. What is JSX
// JSX is basically build tool that convert html tag into JavaScript
// For Example:
ReactDOM.render(
<a href="www.blabla.com">
<img src="https://imgs.xkcd.com/comics/random_number.png" />
</a>,
document.getElementById('app')
);
@nishant8BITS
nishant8BITS / ReactLifeCycle.js
Created January 9, 2018 13:17
1. React Life Cycle
/**
* Initialization
*/
class ContraMusicPlayer extends ReactComponent {
// Setting Initial State in constructor, Which can be change later by using this.setState method
constructor(props){
super(props);
[{"poverty_level": "highest poverty", "school_longitude": -73.910432, "total_donations": 251, "school_latitude": 40.688454, "resource_type": "Supplies", "date_posted": "2002-09-13 00:00:00", "school_county": "Kings (Brooklyn)", "funding_status": "completed", "school_state": "NY"}, {"poverty_level": "moderate poverty", "school_longitude": -73.95076, "total_donations": 125, "school_latitude": 40.770233, "resource_type": "Supplies", "date_posted": "2002-09-16 00:00:00", "school_county": "New York (Manhattan)", "funding_status": "completed", "school_state": "NY"}, {"poverty_level": "highest poverty", "school_longitude": -73.816925, "total_donations": 2110, "school_latitude": 40.729763, "resource_type": "Trips", "date_posted": "2002-09-17 00:00:00", "school_county": "Queens", "funding_status": "completed", "school_state": "NY"}, {"poverty_level": "highest poverty", "school_longitude": -74.01184, "total_donations": 1241, "school_latitude": 40.701778, "resource_type": "Technology", "date_posted": "2002-09-17 00:00:0
@nishant8BITS
nishant8BITS / gist:db713bf49d4efdf259e09b5379e45fa0
Created October 28, 2017 14:12 — forked from belsrc/gist:672b75d1f89a9a5c192c
Simple Vue.js filters that I usually need
/**
* Changes value to past tense.
* Simple filter does not support irregular verbs such as eat-ate, fly-flew, etc.
* http://jsfiddle.net/bryan_k/0xczme2r/
*
* @param {String} value The value string.
*/
Vue.filter('past-tense', function(value) {
// Slightly follows http://www.oxforddictionaries.com/us/words/verb-tenses-adding-ed-and-ing
var vowels = ['a', 'e', 'i', 'o', 'u'];