Skip to content

Instantly share code, notes, and snippets.

View JosephScript's full-sized avatar
💭
🚀 Changed my handle to @JosephScript!

Joseph A. Szczesniak JosephScript

💭
🚀 Changed my handle to @JosephScript!
View GitHub Profile
@JosephScript
JosephScript / authService.js
Created September 22, 2015 14:25
This is an AngularJS authentication service for using JSON Web Tokens
app.service('authService', ['$window', function ($window) {
this.parseJwt = function (token) {
if (token) {
var base64Url = token.split('.')[1];
var base64 = base64Url.replace('-', '+').replace('_', '/');
return JSON.parse($window.atob(base64));
} else return {};
};
@JosephScript
JosephScript / authInterceptor.js
Last active March 14, 2017 05:24
An authorization interceptor for AngularJS. This relies on an authorization service, and will send JWT headers with every request. If a 401 error is encountered, the user is redirected to the login page.
app.factory('authInterceptor', ['$q', '$location', 'authService', function ($q, $location, authService) {
return {
request: function (config) {
config.headers = config.headers || {};
if (authService.isAuthed()) {
config.headers.Authorization = 'Bearer ' + authService.getToken();
}
return config;
},
response: function (response) {
@JosephScript
JosephScript / LoginCtrl.js
Created September 22, 2015 14:33
A login controller for AngularJS. This relies on authService.js for token storage, and retrieval.
app.controller('LoginCtrl', ['$scope', '$http', '$location', 'authService',
function ($scope, $http, $location, authService) {
$scope.submit = function () {
$http.post('/authenticate', this.form)
.success(function (data, status, headers, config) {
// save json web token in session storage
authService.saveToken(data.token);
@JosephScript
JosephScript / catchAll.js
Last active January 29, 2016 18:40
"Catchall" router for angular apps. Include this router LAST.
var express = require('express');
var router = express.Router();
/* handle root angular route redirects */
router.get('/*', function(req, res, next){
var url = req.originalUrl;
if (url.split('.').length > 1){
next();
} else {
// handles angular urls. i.e. anything without a '.' in the url (so static files aren't handled)
@JosephScript
JosephScript / giantBomb.js
Created November 16, 2015 19:58
A simple Giantbomb API request using JSONP for cross origin support.
$.ajax ({
type: 'GET',
dataType: 'jsonp',
crossDomain: true,
jsonp: 'json_callback',
url: 'http://www.giantbomb.com/api/search/?format=jsonp&api_key=[YOUR_API_KEY]&query=batman'
}).done(function(data) {
alert("success:", data);
}).fail(function() {
alert("error");
@JosephScript
JosephScript / talent_create_tables_data.sql
Created January 25, 2016 17:18
Example of a one-to-one, one-to-many, and a many-to-many relationship using PostgreSQL
/** ---------- TALENT ---------- **/
DROP TABLE IF EXISTS talent CASCADE;
CREATE TABLE talent (
talent_id serial PRIMARY KEY,
first_name text,
last_name text,
phone text,
created_at timestamp,
updated_at timestamp
@JosephScript
JosephScript / mail.js
Created June 15, 2018 16:46
Mailgun Zeit Micro Nodejs
const {buffer, text, json} = require('micro')
const Mailgun = require('mailgun-js')
const mailgun = new Mailgun({apiKey: 'api_key', domain: 'domain'})
module.exports = async (req, res) => {
const js = await json(req)
const data = {
from: js.from,
to: '[email protected]',
subject: 'Hello from Mailgun',
#!/bin/bash
# homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
# fonts
brew tap homebrew/cask-fonts
brew cask install font-hack-nerd-font
mkdir -p ~/Source
@JosephScript
JosephScript / nlp.txt
Created December 13, 2019 15:34
NLP example
Example Text: It’s what Chrome is a programming using AngularJS is a lightweight jQuery clone, without leaving the desired DOM in software modules, defined by modular programming, in a Web browsers perform just-in-time compilation Native development. Facebook for a creational pattern was engineered as an API for library/framework free JavaScript is a way to post status updates without leaving the intermediate to help run multiple versions of documents BEM is the current JavaScript. Apache Cordova is a project. Wide Web analytics, ad tracking, personalization or submitting data. Edge browser. Redux is ECMAScript 2015 / ES6 code can run both in Java. HTTP requests. XMLHttpRequest is a JavaScript code linter. JSPM is a structural framework for transferring data flow. SpiderMonkey, is the host environment for many frameworks in the performance limitations inherent to act as individual documentations, but more responsive. Virtual DOM is a library for building interactive 3D content for information about the result
@JosephScript
JosephScript / Animate.tsx
Created March 20, 2020 18:17
An easy way to use CSS transitions in React to animate a child element in and out
import React, { FC, useEffect, useState, ReactNode } from 'react'
import styled from '@emotion/styled'
const FadeInAndOut = styled.p`
transition: opacity 0.5s;
opacity: 0;
&.fadeIn {
opacity: 1;
}
`