Skip to content

Instantly share code, notes, and snippets.

View elitan's full-sized avatar

Johan Eliasson elitan

View GitHub Profile
@stopsatgreen
stopsatgreen / php-get-json.php
Last active May 31, 2019 17:55
PHP: get JSON, with headers
<?php
// Because I don’t use PHP often enough to remember it instantly
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"Accept: application/json"
)
);
$context = stream_context_create($opts);
@defrex
defrex / AuthClient.ts
Last active June 27, 2020 22:39
Nhost Auth & Apollo integrated with Next.js
import fetch from 'cross-fetch'
import jwtDecode from 'jwt-decode'
import moment from 'moment'
import { NextPageContext } from 'next'
import { destroyCookie, parseCookies, setCookie } from 'nookies'
export class AuthClient {
baseUrl = 'https://backend-[whatev].nhost.app'
stateChangeCallbacks: (() => void)[] = []
context?: NextPageContext
@ConProgramming
ConProgramming / pageql.config.js
Created November 13, 2020 00:28
Nhost Svelte Stuffs (file names with - are for / of subdirectory)
import { auth } from "./src/js/nhost.js";
import { initClient, getClient } from "./src/js/graphqlClient.js";
export default {
auth: {
checkRole: (requiredRole) => {
//Used by pageql:authRole directive
//Return false if user's role fails to hit specifications
//Returning false hides the component
@swinton
swinton / AESCipher.py
Last active April 30, 2023 05:48
Encrypt & Decrypt using PyCrypto AES 256 From http://stackoverflow.com/a/12525165/119849
#!/usr/bin/env python
import base64
from Crypto import Random
from Crypto.Cipher import AES
BS = 16
pad = lambda s: s + (BS - len(s) % BS) * chr(BS - len(s) % BS)
unpad = lambda s : s[0:-ord(s[-1])]