Skip to content

Instantly share code, notes, and snippets.

View mihaiserban's full-sized avatar
💭
👨🏻‍💻✨

Mihai Serban mihaiserban

💭
👨🏻‍💻✨
View GitHub Profile
@mihaiserban
mihaiserban / payments.js
Created December 7, 2018 18:40
braintree payments stream search transactions
router.get('/payments', verifyJWT_MW, function(req, res) {
try {
let transactions = [];
const stream = Braintree.gateway.transaction.search(function(search) {
search.customerId().is(req.user.account.braintreeCustomerId);
});
stream.on('ready', function() {
console.log(stream.searchResponse.length());
@mihaiserban
mihaiserban / button.js
Last active December 3, 2018 11:40
Button example v2
/* global window */
import React from "react";
import classNames from "classnames";
const Button = ({
dark,
light,
disabled = false,
onPressed,
width = 200,
@mihaiserban
mihaiserban / aws.js
Created November 2, 2018 14:28
AWS SNS handle SES bounce/complaints
const express = require("express");
const router = express.Router();
const User = require("../models/user");
const AWS = require("aws-sdk");
AWS.config.update({
accessKeyId: process.env.accessKeyId,
secretAccessKey: process.env.secretAccessKey,
region: "us-east-1"
});
@mihaiserban
mihaiserban / encryption.js
Created October 29, 2018 22:01 — forked from vlucas/encryption.js
Stronger Encryption and Decryption in Node.js
'use strict';
const crypto = require('crypto');
const ENCRYPTION_KEY = process.env.ENCRYPTION_KEY; // Must be 256 bytes (32 characters)
const IV_LENGTH = 16; // For AES, this is always 16
function encrypt(text) {
let iv = crypto.randomBytes(IV_LENGTH);
let cipher = crypto.createCipheriv('aes-256-cbc', new Buffer(ENCRYPTION_KEY), iv);
@mihaiserban
mihaiserban / image-react.js
Last active May 17, 2019 09:06
React image fallback - in case src fails try to load a placeholder instead
import React from "react";
import PropTypes from "prop-types";
class Image extends React.Component {
constructor(props) {
super(props);
this.state = { src: props.src };
}
componentWillReceiveProps(nextProps) {
@mihaiserban
mihaiserban / circle.yml
Created October 5, 2018 09:11
Auto deployment to now.sh from Circle CI
machine:
node:
version: 8
deployment:
staging:
branch: master
owner: my-company
commands:
- ./deploy-staging.sh
production:
@mihaiserban
mihaiserban / gist:1f35d488405812f2bbd4b16e38e4afb5
Last active June 27, 2023 03:38
aws s3.listObjects recursive including metadata
const aws = require('aws-sdk')
aws.config.update({
accessKeyId: process.env.aws_access_key_id,
secretAccessKey: process.env.aws_secret_access_key,
region: process.env.aws_region});
const options = {
Bucket: process.env.s3_bucket,
region: process.env.aws_region,
@mihaiserban
mihaiserban / gist:e48b6a90ff6f07ba53255a2d60d8c194
Created June 15, 2018 14:04
Functional input react component
/* global window */
import React from 'react'
import PropTypes from 'prop-types'
const InputField = ({
label = 'Password',
invalidLabel = 'The password field is required.',
placeholder = 'Enter your password',
input,
onSubmit,
@mihaiserban
mihaiserban / react.md
Created May 10, 2018 20:47 — forked from monicao/react.md
React Lifecycle Cheatsheet

React Component Lifecycle

  • getInitialState
  • getDefaultProps
  • componentWillMount
  • componentDidMount
  • shouldComponentUpdate (Update only)
  • componentWillUpdate (Update only)
  • componentWillReceiveProps (Update only)
  • render
@mihaiserban
mihaiserban / config.yml
Created March 10, 2018 09:48
now zeit circleci deployment
version: 2
jobs:
build:
docker:
- image: 'circleci/node:9.7.1'
branches:
only:
- master
steps:
- checkout