Skip to content

Instantly share code, notes, and snippets.

View marshallswain's full-sized avatar
😄

Marshall Thompson marshallswain

😄
View GitHub Profile
@marshallswain
marshallswain / auth-check-access-token.ts
Last active August 5, 2023 19:41
Example FeathersJS auth code. I have not tested it with even a single request. I just didn't want to lose it.
import type { HookContext, NextFunction } from '@feathersjs/feathers'
type GetTokenFn = <H extends HookContext>(context: H) => Promise<string>
interface CheckAccessTokenHookOptions {
getToken?: GetTokenFn | GetTokenFn[]
}
const defaultGetTokenFn: GetTokenFn = async context => context.params.headers?.authorization?.split(' ')[1]
-- See Nauany's full blog post at https://blog.bitovi.com
WITHRECURSIVEx(i)
AS (
VALUES(0)
UNIONALLSELECT i + 1FROM xWHERE i < 101
),
Z(Ix, Iy, Cx, Cy, X, Y, I)
AS (
SELECT Ix, Iy, X::float, Y::float, X::float, Y::float, 0
FROM(SELECT -2.2 + 0.031 * i, iFROM x)AS xgen(x,ix)
@marshallswain
marshallswain / mb.js
Last active October 14, 2018 21:46
mb object property accessor, formatted
const mb = (...p) => o => p.reduce((a, c) => Object(a)[c], o)
@marshallswain
marshallswain / auth.js
Created May 17, 2018 16:16
Next.js Feathers auth trick
jwtAuth({ token }) {
if (!isClient) {
app().set('accessToken', token);
return this.verifyToken(token)
.then(payload => this.loadUser(payload.userId));
}
return app()
.authenticate({ strategy: 'jwt', accessToken: token })
.then(response => this.verifyToken(response.accessToken))
@marshallswain
marshallswain / states.js
Created March 18, 2018 02:01
US States & Abbreviations as JavaScript Array
var usStates = [
{ name: 'ALABAMA', abbreviation: 'AL'},
{ name: 'ALASKA', abbreviation: 'AK'},
{ name: 'AMERICAN SAMOA', abbreviation: 'AS'},
{ name: 'ARIZONA', abbreviation: 'AZ'},
{ name: 'ARKANSAS', abbreviation: 'AR'},
{ name: 'CALIFORNIA', abbreviation: 'CA'},
{ name: 'COLORADO', abbreviation: 'CO'},
{ name: 'CONNECTICUT', abbreviation: 'CT'},
{ name: 'DELAWARE', abbreviation: 'DE'},
@marshallswain
marshallswain / feathers-hooks.json
Last active October 17, 2017 18:08
VS Code Feathers Snippets
{
"Feathers Hook": {
"prefix": ";hook;",
"body": [
"const errors = require('feathers-errors')",
"",
"module.exports = function () {",
" return function $1 (context) {",
" $2",
" }",
@marshallswain
marshallswain / readme.md
Last active October 9, 2017 13:44
Webpack configuration for CanJS

Using Webpack with CanJS

This is a good starting Webpack configuration, but will need to be adjusted to work well in production.

Instructions

  1. Create webpack.config.js in the root of your project. (Refer to the Webpack CLI docs to learn how to customize this))
  2. Install dependencies: npm install webpack webpack-dev-server can-stache-loader svg-inline-loader style-loader less-loader less --save-dev

Cordova: Running an ios app in a specific ios emulator

You need two flags when specifying which target to emulate. Also, do not include the version number on the end.

Find out what emulator images are available. Again, take into account that the version number will not be included when specifying the target in the cordova call.

./platforms/ios/cordova/lib/list-emulator-images

iPhone-5, 10.3
@marshallswain
marshallswain / users.test.js
Created September 13, 2017 19:56
Simple user create test
describe('create', function () {
before(function () {
return utils.services.users.removeByEmail(app, 'test@test.com')
})
it('allows user signup', function (done) {
const newUser = {
email: 'test@test.com',
password: 'test'
}
@marshallswain
marshallswain / app.js
Last active May 18, 2021 17:08
Authenticate on feathers-socketio connection with header
const socketio = require('feathers-socketio')
const authOnSocketConnect = require('./authenticate-on-socket-connect')
// ... Setup your Feathers app code or use the generator then replace the socketio registration with this
// When you register the feathers-socketio plugin, use the utility
app.configure(socketio(function (io) {
// Get Socket.io headers
io.on('connection', function (socket) {
authOnSocketConnect({ app, socket })