Skip to content

Instantly share code, notes, and snippets.

@gengns
gengns / apollo.js
Created October 13, 2021 15:30
Set WebSockets and HTTP authorization with Apollo after getting your token
/**
apollo.js
Set WebSockets and HTTP authorization with Apollo Client after getting your token in your login.
I'm using a Svelte's store here to get the token but you can use Vanilla with sessionStorage or whatever you like
*/
import { ApolloClient } from 'apollo-client'
import { InMemoryCache } from 'apollo-cache-inmemory'
import { HttpLink } from 'apollo-link-http'
import { WebSocketLink } from 'apollo-link-ws'
@gengns
gengns / box.css
Last active August 18, 2018 21:19
Create your own native web component
box-element > div {
color: #555;
background: #00BCD4;
width: 100px;
height: 100px;
display: flex;
justify-content: center;
align-items: center;
}
@gengns
gengns / index.html
Last active August 10, 2018 12:38
Basic translator using Vanilla JavaScript
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
</head>
<body>
<label class="T">Usuario</label>
<label class="T">Contraseña</label>
<select>
<option value="es">Español</option>
<option value="en">English</option>
@gengns
gengns / swap.js
Last active July 8, 2018 15:12
Swap the first and last element in an array without temporary variable or ES6 swap method [a, b] = [b, a]
[a.pop(), ...a.slice(1), a.shift()]
@gengns
gengns / get_html_file.js
Last active May 26, 2020 16:52
Get a local html file to insert into your Cordova Single Page Application
/**
Get local html files (views/widgets) to insert into your SPA
@param path ex:
path = 'file:///android_asset/www/view/page.html'
@param success
@param failure
*/
function get_html_file(path, success, failure) {
const xhr = new XMLHttpRequest()
@gengns
gengns / get_file.js
Last active April 22, 2018 19:53
Get local/external raw files without user interface (input file)
/**
Get local/external files without user interface (input file)
@param path ex:
path = 'file:///storage/emulated/0/Android/data/com.gengns.appname/cache/finn.jpg'
path = 'https://allmyimages.com/jake.jpg'
@param success
@param failure
*/
function getFile(path, success, failure) {