Skip to content

Instantly share code, notes, and snippets.

View saiumesh535's full-sized avatar
🤒
so long

sai umesh saiumesh535

🤒
so long
View GitHub Profile
@saiumesh535
saiumesh535 / app.js
Created November 13, 2017 07:50
Writing custom emitter's in nodejs
// let's code some emitters
function Emitter(){
this.events = {};
}
const emtr = new Emitter();
// on function to push events in array
Emitter.prototype.on = function(type,listener){
this.events[type] = this.events[type] || [];
@saiumesh535
saiumesh535 / idea.js
Created December 2, 2017 14:39
asyncAwaitIdea
async function loginController(){
try{
const a = await loginService().
catch((error)=> {throw new CustomErrorHandler({code: 101, message:"a failed",error: error})});
const b = await someUtil().
catch((error)=> {throw new CustomErrorHandler({code: 102, message:"b failed",error: error})});
//someoeeoe
if(a && b) console.log("no one failed")
}catch(error){
@saiumesh535
saiumesh535 / httpcalls.ts
Last active December 12, 2017 11:49
Angular 4/5 Http calls
// this is example to make http calls in angular 4/5
// not silver bullet to follow but it get's job done
import { HttpClient,HttpHeaders,HttpParams } from '@angular/common/http';
export class SomeHttpService {
constructor(private httpClient: HttpClient){}
// simple get method
@saiumesh535
saiumesh535 / app.js
Created February 10, 2018 19:53
GraphQL very basic example.
const express = require('express');
const graphqlHTTP = require('express-graphql');
const { buildSchema } = require('graphql');
const app = express();
let updatedCount = 0;
let updatedDate = new Date();
class GetCount{
constructor(){
this.counter = updatedCount;
@saiumesh535
saiumesh535 / app.js
Last active February 13, 2018 18:24
connecting MySQL in express nodejs
const express = require('express');
const app = express();
/* requiring middleware */
const { getConnection } = require('./app/middlewares/mysql');
/* connecting mysql before going to requested route */
app.use('/auth', getConnection, require('./app/controllers/auth'));
@saiumesh535
saiumesh535 / manifest.json
Created April 9, 2018 17:56
Angular extension manifest file
{
"manifest_version": 2,
"name": "Extension third party login",
"description": "Let's do some login",
"version": "1.0",
"browser_action": {
"default_icon": "favicon.ico",
"default_popup": "index.html"
},
"permissions": [
@saiumesh535
saiumesh535 / app.js
Last active August 31, 2019 19:57
error handling in express applicaiton
const express = require('express');
const http = require('http');
const app = express();
app.get('/', (req, res) => {
res.send('Hey!!');
});
app.post('/exceptionRoute', async (req, res) => {
@saiumesh535
saiumesh535 / main.rs
Created September 16, 2018 18:39
Basic types and control flow for rust
fn main() {
// defining variable
let name = "Rust!!";
println!("Welcome to {}", name);
// name = "this will throw error";
// that's beacasue by default variables are immutable
// mutation of variables
let mut i_can_mut = 1;
@saiumesh535
saiumesh535 / app.js
Created November 2, 2018 10:35
Serving static HTML files using express node
const path = require('path');
const express = require('express');
const app = express();
const publicPath = path.join(__dirname,'./build');
const port = process.env.PORT || 3001;
app.use(express.static(publicPath));
// write all api routes here
@saiumesh535
saiumesh535 / shuttlecock.ts
Last active November 17, 2018 15:25
Promisify Observable with callback function
import { Observable, of } from "rxjs";
export const promisify = <T>(obser: Observable<T>): Promise<T> => {
return obser.toPromise();
};
function something(func: (...args) => Promise<void>): any {
return func({cockIt: promisify});
}