Skip to content

Instantly share code, notes, and snippets.

View dreamerkumar's full-sized avatar

Vishal Kumar dreamerkumar

View GitHub Profile
@dreamerkumar
dreamerkumar / makit-stand-out.css
Created May 29, 2020 00:42
Are you having a hard time debugging your CSS? Try using this simple line to visualize all of your elements on the page.
* {
outline: solid 0.25rem red !important;
}
@dreamerkumar
dreamerkumar / fetch.js
Created April 21, 2020 21:52
Handle succcess and error responses for fetch calls, including scenarios where network error won't return a response body. Attempt to squeeze out all necessary info from success as well as failures.
fetch('/api/sendMessage', {
method: 'POST',
body: JSON.stringify(bodyObj),
headers: new Headers({
'Content-Type': 'application/json',
}),
})
.then((res) => this.handlePushNotificationResponse(res))
.catch((res) => this.handlePushNotificationResponse(res));
@dreamerkumar
dreamerkumar / crud-with-mongodb-and-node-v8-without-promises.js
Created October 29, 2017 22:27
Logic to implement get list, get, post, put and delete. This one is done without promises. Logic is generic so can be used with any mongoose model
'use strict';
require('./model');
const mongoose = require('mongoose');
const Model = mongoose.model('Rep');
const _ = require('lodash');
const controller = {
@dreamerkumar
dreamerkumar / change_property_nesting_in_json_file.py
Created September 14, 2017 14:29
Python script to change the structure within json files
import json
def updateJsonFile(fileName):
jsonFile = open(fileName, "r") # Open the JSON file for reading
data = json.load(jsonFile) # Read the JSON into the buffer
jsonFile.close() # Close the JSON file
for data1 in data:
if 'property1' in data1:
@dreamerkumar
dreamerkumar / optimized_autocomplete_service.ts
Created September 22, 2016 19:57
angular 2 autocomplete service using rxjs
import {Injectable} from '@angular/core';
import { URLSearchParams, Jsonp } from '@angular/http';
import { Observable } from 'rxjs/Observable';
@Injectable()
export class WikipediaSearchService {
constructor(private jsonp: Jsonp, private url: string) { }
search(terms: Observable<string>, debounceMs = 400) {
return terms.debounceTime(400)
@dreamerkumar
dreamerkumar / scale-size-of-element-or-image.css
Created September 21, 2016 14:56
CSS - Scale the size of an element or image
scaled {
transform: scale(1.05,1.05);
}
@dreamerkumar
dreamerkumar / wait till an element shows up on browser.js
Created August 30, 2016 15:11
e2e protractor test showing how to wait for the browser to reload after mocking an api causes this reload
this.Given(/^My api is mocked with "([^"]*)" mock data$/, function (mockName) {
return mocks.mocking_json[mockName]().then(function () {
return browser.wait(function () {
return myPage.$myWaitElement.isPresent();
}, 30000)
});
});
@dreamerkumar
dreamerkumar / gist:1c0c41b3644ab822461f36ca68a76193
Last active August 29, 2016 20:38
Protractor test to wait for a given number of milliseconds
this.Then(/^Wait for (\d+) milliseconds$/, function (numberOfMilliseconds) {
var d = protractor.promise.defer();
console.log('WAITING 10 SECONDS');
setTimeout(function () {
console.log("fulfill");
d.fulfill('ok');
}, numberOfMilliseconds);
return d;
});
'use strict';
(function() {
angular.module('mymodule', [
.....
])
.config([
@dreamerkumar
dreamerkumar / root-file-for-angular-app.html
Created August 17, 2016 18:01
Important markup within head tag to enable routing for an angular 2 app
<head>
<base href="/">