Skip to content

Instantly share code, notes, and snippets.

@amit08255
amit08255 / intercept.js
Created June 16, 2022 06:26 — forked from suprememoocow/intercept.js
AJAX timing interceptor: this class intercepts all AJAX calls and records the time taken for the HTTP request to complete. These timings are posted back to the server in batches, if there are any to send, about every two seconds. Tested in Firefox, Chrome
(function(XHR) {
"use strict";
var stats = [];
var timeoutId = null;
var open = XHR.prototype.open;
var send = XHR.prototype.send;
// company.ts
import { arg, extendType, inputObjectType, intArg, list, nonNull, objectType, stringArg } from "nexus";
export const CompanyInputType = inputObjectType({
name: 'CompanyInputType',
definition(t) {
t.string('name')
t.string('contactPerson')
t.string('bio')
@amit08255
amit08255 / download-file.js
Created December 1, 2021 08:59 — forked from javilobo8/download-file.js
Download files with AJAX (axios)
axios({
url: 'http://localhost:5000/static/example.pdf',
method: 'GET',
responseType: 'blob', // important
}).then((response) => {
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'file.pdf');
document.body.appendChild(link);
@amit08255
amit08255 / linkedList.js
Created November 16, 2021 16:34 — forked from codesections/linkedList.js
A simple linked list implemented in JavaScript
const LinkedList = function() {
this.head = null;
this.tail = null;
};
LinkedList.prototype.addToTail = function(value) {
const newTail = { value, next: null };
if (this.tail) {
this.tail.next = newTail;
@amit08255
amit08255 / react-phone-book.js
Created October 23, 2021 05:21 — forked from roshanlabh/react-phone-book.js
Coderbyte - React Phone Book [solution]
import React, { useState } from "react";
import ReactDOM from "react-dom";
const style = {
table: {
borderCollapse: "collapse",
},
tableCell: {
border: "1px solid gray",
margin: 0,
@amit08255
amit08255 / PreventCopyPaste.js
Last active October 6, 2021 08:49 — forked from ststeiger/PreventCopyPaste.js
Prevent copy-paste and contextmenu
document.oncontextmenu = function(event) {
event.preventDefault();
event.stopPropagation();
return false;
};
document.addEventListener('contextmenu', function(event){
event.preventDefault();
event.stopPropagation();
@amit08255
amit08255 / bithack.cc
Created July 24, 2021 11:47 — forked from stephenLee/bithack.cc
bit manipulation tricks(collections)
/*
* Reference:
* http://www.quora.com/Computer-Programming/What-are-some-cool-bit-manipulation-tricks-hacks
* http://www.catonmat.net/blog/low-level-bit-hacks-you-absolutely-must-know/
*/
#include <iostream>
#include <string.h>
using namespace std;
@amit08255
amit08255 / examples.js
Created July 4, 2021 07:03 — forked from dypsilon/examples.js
Lazy Continuation Monad in JavaScript
const Cont = require('./lazy-continuation');
// pointed version
const c = Cont.of(5) // initial value
.chain((x) => {
return Cont.of(x + 5); // synchronous computation
})
.chain((x) => { // async computation
return new Cont((resolve) => {
setTimeout(() => resolve(x + 15), 500);
/*
* RC4 symmetric cipher encryption/decryption
*
* @license Public Domain
* @param string key - secret key for encryption/decryption
* @param string str - string to be encrypted/decrypted
* @return string
*/
function rc4(key, str) {
var s = [], j = 0, x, res = '';
@amit08255
amit08255 / rc4.js
Created June 16, 2021 07:42 — forked from farhadi/rc4.js
RC4 encryption in javascript and php
/*
* RC4 symmetric cipher encryption/decryption
*
* @license Public Domain
* @param string key - secret key for encryption/decryption
* @param string str - string to be encrypted/decrypted
* @return string
*/
function rc4(key, str) {
var s = [], j = 0, x, res = '';