Skip to content

Instantly share code, notes, and snippets.

View ianfabs's full-sized avatar

Ian Fabs ianfabs

View GitHub Profile
@ianfabs
ianfabs / sleep.js
Created March 2, 2019 06:41
A tiny module that implements sleep in javascript
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
module.exports = sleep;
@ianfabs
ianfabs / objectify.js
Created March 2, 2019 01:56
This function solves an issue i was experiencing on a project where mongoose wasn't correctly returning an object for graphql resolvers. This fixes that issue by returning a new version of the object supplied to the function and converting the object id to a string.
//long version
const objectify = object => (
object.isArray()
?
object.map(element => objectify(element))
:
({
...object.toObject(),
_id: object._id.toString(),
})
@ianfabs
ianfabs / db.js
Last active April 9, 2019 16:54
A really really REAAAALLLY tiny DB I made for testing things, works great with graphql apis :-)
// Do not use this class yet, please just use the Collection class
class DB {
constructor(collections) {
if (
collections !== null &&
collections !== undefined &&
collections !== []
) {
//this._db = collections.map((s, i) => ({ ...s, id: i }));
if (collections instanceof Object) {
@ianfabs
ianfabs / jraph.ts
Created October 22, 2018 04:29
jraph - a simple fetch wrapper for GraphQL, just to tidy up the look of things!
async function jraph(argv: JraphOptions){
let url = argv.url;
let headers = { 'Content-Type': 'application/json' }
let body = JSON.stringify({query: argv.query});
let fetch_options = {
method: argv.method,
headers,
body
};
//returns request as JSON
@ianfabs
ianfabs / jgraph.ts
Created October 22, 2018 04:18
jgraph: a simple typescript-based fetch api for GraphQL, to make it a bit easier to use semantically
interface JraphOptions{
url: string;
method: "post" | "POST" | "get" | "GET" | "put" | "PUT" | "delete" | "DELETE";
query: string;
}
async function jraph(argv: JraphOptions){
let url = argv.url;
let headers = { 'Content-Type': 'application/json' }
let body = JSON.stringify({query: argv.query});
@ianfabs
ianfabs / setup.sh
Created September 20, 2018 17:01
Just a script to install the things I need for work, since I switch computers a lot
#!/bin/bash
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg
# Install repo
sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list.d/vscode.list'
# Update apt-get
sudo apt-get update
# Install
sudo apt-get install code-insiders
@ianfabs
ianfabs / jesus_people_are_wild.txt
Created September 20, 2018 15:06
This is a forum i found about people complaining about inspect element and it's REALLY cringy
https://answers.microsoft.com/en-us/ie/forum/ie11-iewindows_10/inspect-element-in-edge-why/64704ef0-4880-44df-b9c2-d90d8a34885d
@ianfabs
ianfabs / index.html
Last active September 18, 2018 18:15
A simple, efficient, redirect page to hide directory content 👌 Just slap this bad-boy into the directory you want to hide, then change the content of the META tag to the path you'd like to move to and BLAM - done 😁
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta name="redirect" content="./path/to/redirect/">
<title>304 Permanent Redirect</title>
</head>
<body>
@ianfabs
ianfabs / Vinyl.vue
Created September 9, 2018 23:37
A CSS, JS, and HTML Turntable
<template>
<div id="root">
<center>
<div id="turntable">
<div id="table-shadow"></div>
<div id="table-feet"></div>
<div id="wood">
<div id="grain1"></div>
<div id="grain2"></div>
<div id="grain3"></div>
@ianfabs
ianfabs / json-sort-by-key.js
Created September 8, 2018 21:02
Sort a JSON Array by a key
function GetSortOrder(prop) {
return function(a, b) {
if (a[prop] > b[prop]) {
return 1;
} else if (a[prop] < b[prop]) {
return -1;
}
return 0;
}
}