Skip to content

Instantly share code, notes, and snippets.

View alexanmtz's full-sized avatar
🎯
Focusing

Alexandre Magno alexanmtz

🎯
Focusing
View GitHub Profile
@alexanmtz
alexanmtz / SparkPost cURL Create (POST) Transmissions API Example
Created December 21, 2017 19:18 — forked from bdeanindy/SparkPost cURL Create (POST) Transmissions API Example
cURL POST Example to send an email using the SparkPost Transmissions API
curl \
-H "Content-Type: application/json" \
-H "Authorization: <REPLACE_WITH_YOUR_API_KEY>" \
-X POST -d '{"options":{"open_tracking":true,"click_tracking":true},"return_path":"bounces@<REPLACE_WITH_YOUR_SENDING_DOMAIN_HERE>","metadata":{"some_useful_metadata":"testing_sparkpost"},"substitution_data":{"signature":"<REPLACE_WITH_YOUR_FIRST_AND_LAST_NAME>"},"recipients":[{"address":{"email":"<REPLACE_WITH_YOUR_EMAIL_ADDRESS>","tags":["learning"],"substitution_data":{"customer_type":"Platinum","first_name":"<REPLACE_WITH_YOUR_FIRST_NAME>"}}}],"content":{"from":{"name":"Awesome Company","email":"testing@<REPLACE_WITH_YOUR_SENDING_DOMAIN>"},"subject":"My first SparkPost Transmission","reply_to":"Awesome Company ","text":"Hi {{address.first_name}}\r\nYou have just sent your first email through SparkPost!\r\nCongratulations,\r\n{{signature}}","html":"<strong>Hi {{address.first_name}},</strong><p>You have just sent your first email through SparkPost!</p><p>Congratulations!</p>{{signature}}"}}' \
https://api.sparkpos
@alexanmtz
alexanmtz / credit_card.rb
Last active August 25, 2022 19:44
Erro ao chamar send_email: *** ActiveRecord::RecordInvalid Exception: A validação falhou: User é obrigatório(a)
class Payment::PostProcessing::CreditCard
def initialize(transaction)
@transaction = transaction
end
def after_payment(order)
@order = order
register_amount_paid
@order.pay!
save_credit_card
@alexanmtz
alexanmtz / heroku_env_copy.sh
Created August 1, 2018 11:10 — forked from nabucosound/heroku_env_copy.sh
Script to copy environment variables from an existing heroku app to another one
#!/bin/bash
# Source: http://blog.nonuby.com/blog/2012/07/05/copying-env-vars-from-one-heroku-app-to-another/
set -e
sourceApp="$1"
targetApp="$2"
while read key value; do
@alexanmtz
alexanmtz / checkout-form.js
Created September 12, 2018 18:10
A example of a simple CheckoutForm with React
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { injectStripe } from 'react-stripe-elements'
class CheckoutForm extends Component {
constructor (props) {
super(props)
this.handleSubmit = this.handleSubmit.bind(this)
this.onChange = this.onChange.bind(this)
@alexanmtz
alexanmtz / checkout.component.test.js
Created September 14, 2018 20:49
Jest component testing using Enzyme with React
import React from 'react'
import { CheckoutFormPure } from '../../src/components/checkout/checkout-form'
import { mount, configure } from 'enzyme'
import Adapter from 'enzyme-adapter-react-15'
configure({ adapter: new Adapter() })
describe('components', () => {
describe('checkout component', () => {
it('should start a new checkout form with empty state', () => {
@alexanmtz
alexanmtz / chips.jsx
Created October 22, 2018 19:27
Improve a react JSX code
<div className={ classes.chipContainer }>
<Chip
label=' daqui uma semana '
className={ classes.chip }
onClick={ () => this.pickTaskDeadline(7) }
/>
<Chip
label=' daqui quinze dias '
className={ classes.chip }
onClick={ () => this.pickTaskDeadline(15) }
@alexanmtz
alexanmtz / device.py
Created December 4, 2018 19:04
A NodeMCU Micropython script that connects on Wifi and send values about humidity
import network
from machine import ADC
from machine import Timer
import urequests
import os
secret = os.environ['SECRET']
def send_sensor_values():
adc = ADC(0)
@alexanmtz
alexanmtz / server.js
Created December 4, 2018 19:11
A server that will receive a route sensor with credentials to notify by e-mail the user
const express = require('express')
const app = express()
const cors = require('cors')
const bodyParser = require('body-parser')
const Notify = require('./mail')
if (process.env.NODE_ENV !== 'production') {
require('dotenv').config()
app.use(cors())
}
@alexanmtz
alexanmtz / git-export
Created January 2, 2019 10:01 — forked from kristofferh/git-export
"Export" a git repository to zip file
git archive --format zip --output /full/path/to/zipfile.zip master
@alexanmtz
alexanmtz / passport.js
Created January 13, 2019 20:42
Authentication with Node.js, Express, Sequelize, JWT and webtokens
const {
github
} = require('./secrets')
const passport = require('passport')
const gitHubStrategy = require('passport-github2').Strategy
const LocalStrategy = require('passport-local').Strategy
const passportJWT = require('passport-jwt')
const ExtractJWT = passportJWT.ExtractJwt
const JWTStrategy = passportJWT.Strategy
const jwt = require('jsonwebtoken')