Skip to content

Instantly share code, notes, and snippets.

View ricardocanelas's full-sized avatar
🦈

Ricardo Canelas ricardocanelas

🦈
View GitHub Profile
@amoshydra
amoshydra / CollatePages.js
Created November 23, 2018 02:48
A script to consolidate pdf consisting of a set of even and a set of odd pages into a single correct paginated PDF file
// Complements: Planet PDF (http://www.planetpdf.com/)
// Source: https://forums.adobe.com/thread/286654?start=40&tstart=0
// Modified by
// - Christian Sass for Acrobat XI compatibility
// - Bernd Alheit for newer Acrobat compatibility
// - amoshydra for comsolidating solution
// Add a menu item to reverse all pages in the active document
app.addToolButton({ cName: "Reverse", cLabel: "Reverse", cExec: "PPReversePages();", cEnable: "event.rc = (event.target != null);"});
app.addToolButton({ cName: "Collate", cLabel: "Collate", cExec: "trustedCollatePages();", cEnable: "event.rc = (event.target != null);"});
@devishot
devishot / create_react_app__babel_relay.js
Last active November 25, 2018 18:21
Fix for new version of "babel-preset-react-app": "^6.1.0". Original script was taken from https://hackernoon.com/using-create-react-app-with-relay-modern-989c078fa892
const fs = require('fs');
const path = require('path');
const file = path.resolve('./node_modules/babel-preset-react-app/create.js');
var text = fs.readFileSync(file, 'utf8');
if (!text.includes('babel-plugin-relay')) {
if (text.includes("require('babel-plugin-macros'),")) {
text = text.replace(
"require('babel-plugin-macros'),",
@diegohaz
diegohaz / Button.jsx
Last active September 11, 2019 21:15
Reakit Hooks API
import React from "react";
import { useButton, mergeProps } from "reakit";
function Button(props) {
// useButton should be used when the props are being applied to a non-button element
const button = useButton();
return <div {...mergeProps(button, props)} />;
}
// return value of useButton
@whoisryosuke
whoisryosuke / nextjs-hoc-authorization.js
Created June 26, 2018 22:24
ReactJS - NextJS - A HOC for wrapping NextJS pages in an authentication check. Checks for getInitialProps on the child component and runs it, so you still get SSR from the page. Also includes a user agent for Material UI.
import React, {Component} from 'react'
import Router from 'next/router'
import AuthService from './AuthService'
export default function withAuth(AuthComponent) {
const Auth = new AuthService('http://localhost')
return class Authenticated extends Component {
static async getInitialProps(ctx) {
// Ensures material-ui renders the correct css prefixes server-side
@detroitenglish
detroitenglish / zxcvbn-haveibeenpwned-pw-check.js
Last active January 10, 2020 00:04
Fastify Handler: Password Scoring with zxcvbn + haveibeenpwned Range Query API
import zxcvbn from 'zxcvbn'
import axios from 'axios'
import crypto from 'crypto'
// Input is first validated via native Fastify JSON-schema declaration
export async function passwordStrengthChecker(req, reply) {
const { password } = req.body
let message, pwned, ok
let { score } = zxcvbn(password)
try {
// POLYFILLS
// Event.composedPath
// Possibly normalize to add window to Safari's chain, as it does not?
(function(E, d, w) {
if(!E.composedPath) {
E.composedPath = function() {
if (this.path) {
return this.path;
}
var target = this.target;

How we incorporate next and cloudfront (2018-04-21)

Feel free to contact me at [email protected] or tweet at me @statisticsftw

This is a rough outline of how we utilize next.js and S3/Cloudfront. Hope it helps!

It assumes some knowledge of AWS.

Goals

@Awea
Awea / docker-compose.yml
Created March 21, 2018 12:28
Docker compose: PHP (5.4), composer, Apache, MySQL and phpMyAdmin
version: '3'
services:
api:
image: alterway/php:5.4-apache
environment:
PHP_php5enmod: 'mysqli'
HTTPD_a2enmod: 'rewrite headers'
volumes:
# ./api contains my PHP application
- "./api:/var/www/html"
@jsjoeio
jsjoeio / comparison.md
Last active October 10, 2024 14:09
axios vs. isomorphic-fetch

Which library should you use for making HTTP requests from a React/Node project?

In this doc, we'll explore two popular libraries: axios and isomorphic-fetch.

axios

Quick facts:

  • 37,439 stars on GitHub
  • 130 contributors
  • most recent commit: March 8th, 2018
  • created in Aug. 2014
@cklanac
cklanac / challenge-09-many-to-many.md
Last active June 26, 2024 18:32
Challenge 09: KnexJS with Many-to-Many

Noteful Challenge - Many-to-Many

In this challenge you will create a tags and notes_tags table which will setup a many-to-many relationship between notes and tags. You'll also create a new router to perform CRUD operations on the tags, and update the existing notes endpoints to work with tag related data.

Requirements

Add tags and notes_tags table and relationships

To get started, let's update the .sql script from the previous challenges. Create a tags table and define 2 fields in the schema.