Skip to content

Instantly share code, notes, and snippets.

View jaskiratr's full-sized avatar

Jaskirat Randhawa jaskiratr

View GitHub Profile
@jaskiratr
jaskiratr / index.js
Created March 19, 2024 15:41
Testing New Relic Log Endpoint with Compute
/// <reference types="@fastly/js-compute" />
import { Logger } from 'fastly:logger';
addEventListener('fetch', (event) => event.respondWith(handleRequest(event)));
async function handleRequest(event) {
const logger = new Logger('my_new_relic_endpoint');
let logOutput = {
{"version":1,"resource":"file:///d%3A/Git/Senscity-Gitlab/senscity-design-system/src/components/cds-search/cds-search.stories.mdx","entries":[{"id":"jRUh.mdx","source":"searchReplace.source","timestamp":1653600241674},{"id":"cD3A.mdx","source":"searchReplace.source","timestamp":1654310379497},{"id":"E9jH.mdx","source":"searchReplace.source","timestamp":1654310439893},{"id":"h8jf.mdx","source":"moved.source","timestamp":1654310871436},{"id":"yrIl.mdx","source":"renamed.source","timestamp":1654310942169},{"id":"eMEG.mdx","source":"searchReplace.source","timestamp":1654312199578}]}
@jaskiratr
jaskiratr / stream-triangles.js
Last active August 4, 2018 05:09
Triangle grid stream based on Turf.js triangle grid function.
"use strict"
exports.__esModule = true
var distance_1 = require("@turf/distance")
var intersect_1 = require("@turf/intersect")
var helpers_1 = require("@turf/helpers")
/**
* Takes a bounding box and a cell depth and returns a set of triangular {@link Polygon|polygons} in a grid.
*
* @name triangleGrid
* @param {Array<number>} bbox extent in [minX, minY, maxX, maxY] order
@jaskiratr
jaskiratr / chmod-400.cmd
Created June 29, 2018 01:03
Set permission of file equivalent to chmod 400 on Windows.
# Source: https://stackoverflow.com/a/43317244
$path = ".\aws-ec2-key.pem"
# Reset to remove explict permissions
icacls.exe $path /reset
# Give current user explicit read-permission
icacls.exe $path /GRANT:R "$($env:USERNAME):(R)"
# Disable inheritance and remove inherited permissions
icacls.exe $path /inheritance:r
@jaskiratr
jaskiratr / mapboxDataset.js
Created April 16, 2017 03:59
Mapbox Datasets API
var request = require('request-promise')
var AWS = require('aws-sdk')
var fs = require('fs')
var userName = 'YOUR_MAPBOX_USERNAME'
var accessToken = 'YOUR_MAPBOX_TOKEN' // From https://www.mapbox.com/studio/account/tokens/
var credentials = null
/*
Methods:
@jaskiratr
jaskiratr / convertJson.js
Last active April 10, 2017 05:00
Convert JSON to geoJSON
/*
Warning : This is overwrite .geojson filename in the directory with same filename as .json file
To run the script:
node convertJson.js <JSON Filename without extension>
*/
var Readable = require('stream').Readable
@jaskiratr
jaskiratr / gulpfile.js
Last active January 9, 2017 08:05
Express Gulp File
var gulp = require('gulp');
var exec = require('child_process').exec;
var sass = require('gulp-sass');
var nodemon = require('gulp-nodemon');
var browserSync = require('browser-sync').create();
var reload = browserSync.reload;
gulp.task('default', ['sass', 'browser-sync'], function() {
gulp.watch("public/scss/*.scss", ['sass'], reload);
@jaskiratr
jaskiratr / promise_while_loop.js
Created January 3, 2017 22:48 — forked from victorquinn/promise_while_loop.js
Promise "loop" using the Bluebird library
var Promise = require('bluebird');
var promiseWhile = function(condition, action) {
var resolver = Promise.defer();
var loop = function() {
if (!condition()) return resolver.resolve();
return Promise.cast(action())
.then(loop)
.catch(resolver.reject);
[
{
"LexicalDiversity": 5.088301198008541,
"freqDist": [
{
"word": "I",
"count": "2066"
},
{
"word": "Mr",
@jaskiratr
jaskiratr / Chipotle_a_love_script.js
Last active March 28, 2020 19:47
Automating online card game using browser script (https://www.alovestorygame.com/)
// Step 1: Type this in your browser console
var script = document.createElement('script');
script.src = "https://ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(script);
// Wait for a second
//Step 2: Run the following
var elements = $(".card .face-front img");
elements = elements.sort(function(a, b) {