Skip to content

Instantly share code, notes, and snippets.

View xeoncross's full-sized avatar

David Pennington xeoncross

View GitHub Profile
@xeoncross
xeoncross / ubuntu_setup.sh
Last active October 14, 2019 18:23
Setup a new user on Ubuntu 18+ VPS
# Assuming you are logged in as root and the ssh key you want to use already installed for root (i.e. new Digital Ocean VPS)
adduser deploy
usermod -aG sudo deploy
mkdir /home/deploy/.ssh
cp /root/.ssh/authorized_keys /home/deploy/.ssh/
chmod 700 /home/deploy/.ssh
chown deploy:deploy -R /home/deploy/.ssh
/**
* subscriptions data format:
* { eventType: { id: callback } }
*/
const subscriptions = { }
const getNextUniqueId = getIdGenerator()
function subscribe(eventType, callback) {
const id = getNextUniqueId()
@xeoncross
xeoncross / sed cheatsheet
Created October 9, 2019 15:13 — forked from un33k/sed cheatsheet
magic of sed -- find and replace "text" in a string or a file
FILE SPACING:
# double space a file
sed G
# double space a file which already has blank lines in it. Output file
# should contain no more than one blank line between lines of text.
sed '/^$/d;G'
@xeoncross
xeoncross / oauth_token.go
Created September 23, 2019 16:20
Simple OAuth token with auto-renew based on a client id and secret
package oauthtoken
import (
"context"
"encoding/json"
"fmt"
"log"
"net/http"
"net/url"
"strings"
@xeoncross
xeoncross / size_of_slice.go
Created September 18, 2019 17:09
How much memory does a slice of random strings actually take?
package main
import (
"fmt"
"math/rand"
"unsafe"
)
// Thanks to Kale, Andrei, and Jaden on gophers slack
@xeoncross
xeoncross / styles.less
Created September 16, 2019 17:19
Remove extra colors from Atom IDE solorized theme
# Select Solarized Light Syntax theme
# open styles.less and add the following
.syntax--variable,
.syntax--storage,
.syntax--entity,
.syntax--name,
.syntax--type {
color: #657b83 !important;
}
@xeoncross
xeoncross / javascript_encryption.md
Created September 4, 2019 15:35
Javascript Encryption
@xeoncross
xeoncross / mock_http_client.go
Last active August 14, 2019 16:09
Simple wrapper to use for testing when you need a custom http.Client for faking network requests
// https://golang.org/pkg/net/http/#Client
type MockClient struct {
Body interface{}
DoFunc func(req *http.Request) (*http.Response, error)
}
func (m *MockClient) Do(req *http.Request) (*http.Response, error) {
if m.DoFunc != nil {
import { useState } from 'react';
// Usage
function App() {
// Similar to useState but first arg is key to the value in local storage.
const [name, setName] = useLocalStorage('name', 'Bob');
return (
<div>
<input
import * as React from 'react';
import Axios, { AxiosInstance } from 'axios';
import { createContext, consume } from '../lib/context-utils';
import { AuthContext } from './AuthProvider';
export const ApiContext = createContext('apiContext', {
api: undefined as AxiosInstance | undefined,
auth: undefined as React.ContextType<typeof AuthContext> | undefined,
})