Skip to content

Instantly share code, notes, and snippets.

View magician11's full-sized avatar

A magician11

  • Golightly+
  • New Zealand
View GitHub Profile
@magician11
magician11 / goforself.me
Last active March 1, 2018 19:33
Server block example for a WordPress site on Nginx on a DigitalOcean droplet
server {
server_name www.goforself.me goforself.me;
listen 80;
client_max_body_size 20M;
port_in_redirect off;
access_log /var/log/nginx/goforself.me.access.log;
error_log /var/log/nginx/goforself.me.error.log error;
root /var/www/goforself;
index index.php;
@magician11
magician11 / config.js
Last active December 2, 2017 14:03
How to send an email from Node.js using Gmail
module.exports = {
email: {
address: 'youraddress@gmail.com',
password: 'clever-password'
}
};
@magician11
magician11 / google-oauth.js
Last active November 12, 2017 13:29
How to get a new Google access token from a refresh token on Node.js
const axios = require('axios');
const querystring = require('querystring');
const keys = require('../config/keys');
const getAccessToken = async refreshToken => {
try {
const accessTokenObj = await axios.post(
'https://www.googleapis.com/oauth2/v4/token',
querystring.stringify({
refresh_token: refreshToken,
@magician11
magician11 / front-end.js
Last active August 2, 2017 21:36
How To Use jQuery To Post A CSV File To A Node.js Server
// using jQuery
$("#2020data").submit(function(e) {
$.ajax({
url: "https://e0d92634.ngrok.io/test",
type: "POST",
data: new FormData(this),
processData: false,
contentType: false
});
@magician11
magician11 / headless-chrome.js
Last active August 12, 2020 13:03
How to grab the page source from any dynamically generated webpage and then process it .
const CDP = require('chrome-remote-interface');
const chromeLauncher = require('chrome-launcher');
const cheerio = require('cheerio');
(async function() {
const launchChrome = () =>
chromeLauncher.launch({ chromeFlags: ['--disable-gpu', '--headless'] });
const chrome = await launchChrome();
const protocol = await CDP({ port: chrome.port });
@magician11
magician11 / remove-paypal-gateway.rb
Last active May 18, 2022 07:03
How to remove the PayPal payment gateway in Shopify if a product is tagged with 'no-paypal'.
has_no_paypal_tag = Input.cart.line_items.any? { |line_item| line_item.variant.product.tags.include?('no-paypal') }
if has_no_paypal_tag
Output.payment_gateways = Input.payment_gateways.delete_if { |payment_gateway| payment_gateway.name.include?("PayPal") }
else
Output.payment_gateways = Input.payment_gateways
end
@magician11
magician11 / json-over-soap-wrapper.js
Last active December 4, 2018 14:22
How to a JSON API Wrapper for SOAP
const express = require('express');
const https = require('https');
const fs = require('fs');
const cors = require('cors');
const rpn = require('request-promise-native');
const bodyParser = require('body-parser');
/* eslint-disable comma-dangle,arrow-parens,max-len,no-console */
const app = express();
@magician11
magician11 / currency-conversion.html
Last active December 30, 2022 02:57
How To Create Your Own Currency Conversion App
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Currency Conversion</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
crossorigin="anonymous">
@magician11
magician11 / regex-with-variables.js
Created March 17, 2017 10:31
How to use variables in regular expressions in JavaScript.
function getURL(startMatch, endMatch, str) {
var regex = new RegExp(startMatch + ': (.+), ' + endMatch);
var contents = str.split(regex)[1];
return contents ? contents : 'none found';
}
var str = 'website: http://www.google.com, soundcloud: http://www.soundcloud.com, facebook: http://www.facebook.com, stage: the main one';
console.log('Website URL:', getURL('website', 'soundcloud', str));
@magician11
magician11 / secure-node-server.js
Last active December 15, 2016 04:46
How to add https to your Node.js server
// libraries
const express = require('express');
const https = require('https');
const fs = require('fs');
const cors = require('cors'); // Cross-Origin Resource Sharing
// setup express
const app = express();
app.use(cors());