Skip to content

Instantly share code, notes, and snippets.

View avishwakarma's full-sized avatar

Ashok Vishwakarma ✪ avishwakarma

View GitHub Profile
@avishwakarma
avishwakarma / http.ts
Last active July 27, 2022 12:44
A simple utility to make HTTP calls using XMLHttpRequest
export interface HttpResponse<T> {
data: T;
url: string;
status: number;
}
export type HttpMethod = "GET" | "POST" | "PUT" | "DELETE";
export type HttpHaders = { [key: string]: string };
export type QueryParams = { [key: string]: string };
export type HttpBody = Document | XMLHttpRequestBodyInit | null;
// Adding some styles with transitions
const style = document.createElement('style');
const initialScale = 0.4;
style.innerHTML = `
portal {
position:fixed;
width: 100%;
height: 100%;
opacity: 0;
transition:
@avishwakarma
avishwakarma / preact-lazy-load-image.js
Last active January 3, 2020 05:24
Lazy load images in Preact using Intersection Observer
import { h, Component } from 'preact';
import classy from 'classnames';
export default class Image extends Component {
state = {
src: 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7',
dataSrc: false,
loaded: false
}
@avishwakarma
avishwakarma / server.ts
Created March 2, 2019 14:32
Angular Universal KoaJS server
import * as Koa from 'koa';
import * as serve from 'koa-static';
import { readFileSync } from 'fs';
import { join } from 'path';
// the middileware universal.ts
// https://gist.github.com/ashokvishwakarma/7c97578108e49fb38d06777e8319bb24
import universal from './universal';
@avishwakarma
avishwakarma / universal.ts
Last active March 2, 2019 15:09
Angular Universal middleware for KoaJS
import { Context } from 'koa';
import { renderModuleFactory } from '@angular/platform-server';
import { enableProdMode } from '@angular/core';
import { provideModuleMap } from '@nguniversal/module-map-ngfactory-loader';
import { readFileSync } from 'fs';
import { join } from 'path';
const {
@avishwakarma
avishwakarma / schema.graphql
Last active February 6, 2019 16:45
DgraphKoa Generated Types, Inputs, Queries and Mutations
// Types
type Person {
id: ID!
name: String
children(
first: Int
after: Int
filter: PersonFilter
): [Person!]!
parents(
@avishwakarma
avishwakarma / app.service.ts
Created February 4, 2019 11:36
Simple Angular Service example with GraphQL Queries, Mutations and Subscriptions using Apollo Client for Angular
import { Injectable } from '@angular/core';
import { Apollo } from 'apollo-angular';
import {
QUERY_USERS,
MUTATION_LOGIN,
SUBSCRIPTION_POST
} from './graphql';
@Injectable({
@avishwakarma
avishwakarma / app.module.ts
Created February 4, 2019 10:15
Apollo Client implementaion in Angular
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { Subscription } from 'rxjs';
import { ApolloModule, Apollo } from 'apollo-angular';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { setContext } from 'apollo-link-context';
import { onError } from 'apollo-link-error';
import { ApolloLink, split } from 'apollo-link';
import { HttpLink } from 'apollo-link-http';
#!/bin/bash
CLEAN="clean"
RUN="run"
STOP="stop"
if [ "$#" -eq 0 ] || [ $1 = "-h" ] || [ $1 = "--help" ]; then
echo "Usage: ./myapp [OPTIONS] COMMAND [arg...]"
echo " ./myapp [ -h | --help ]"
echo ""
# Install node v10
FROM node:10
# Set the workdir /var/www/myapp
WORKDIR /var/www/myapp
# Copy the package.json to workdir
COPY package.json ./
# Run npm install - install the npm dependencies