Skip to content

Instantly share code, notes, and snippets.

✍️
dev manager by day, writing code at night

Alex Bachuk abachuk

✍️
dev manager by day, writing code at night
Block or report user

Report or block abachuk

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View localStorage-expiration.js
// let's define our expiration date
const today = new Date();
let expDate = new Date();
expDate.setDate(today.getDate() + 30); // 30 days expiration
// a searches user does in your app on the first visit, we collect them to save to localStorage
const userRecentlocations = [
{ city: "New York", country: "US", id: "2390230" },
{ city: "Athens", country: "GR", id: "304802" },
{ city: "Kyiv", country: "UA", id: "1239488" }
View localStorage.js
const fruits = {
apples: 3,
bananas: 4,
pears: 1,
blackberries: 8
}
// always check if Storage is available
if (typeof(Storage)) {
// saving the object (or JSON) to localStorage
View UserSigninHandlerAWSLambda.js
import AWS from 'aws-sdk';
import { CognitoUserPool, AuthenticationDetails, CognitoUser } from 'amazon-cognito-identity-js';
export default function signinHandler(body) {
const authData = JSON.parse(body);
AWS.config.region = 'us-east-1';
const authenticationDetails = {
Username: authData.username,
Password: authData.password,
};
View UserSignupHandler.js
// after all babel and webpack configs
import AWS from 'aws-sdk';
import { CognitoUserPool } from 'amazon-cognito-identity-js';
export default function signupHandler(body) {
const userData = JSON.parse(body);
AWS.config.region = 'us-east-1';
const poolData = {
View treeshaking.js
// modules.js
export function drive(props) {
return props.gas
}
export function fly(props) {
return props.miles
}
// main.js
View getPostsReducerComplete.test.js
import reducer from './getPostReducer';
import * as actions from '../actions/posts/getPost';
import { UPDATE_POST_SUCCESS } from '../actions/posts/updatePost';
import expect from 'expect';
import getPostMock from '../mocks/getPostMock';
describe('post reducer', () => {
it('should return the initial state', () => {
expect(reducer(undefined, {})).toEqual({});
});
View getPostsReducer.test.js
import reducer from './getPostsReducer';
import * as types from '../actions/posts/getPostsReduxAction';
import expect from 'expect';
describe('team reducer', () => {
it('should return the initial state');
it('should handle GET_POST_SUCCESS');
it('should handle UPDATE_POST_SUCCESS');
it('should handle GET_POST_FAIL');
it('should handle GET_POST_START');
View getPostsReduxAction.test.js
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import moxios from 'moxios';
import expect from 'expect';
import * as actions from './getPosts';
import getPostsMock from '../../mocks/getPostsMock';
const middlewares = [thunk];
const mockStore = configureMockStore(middlewares);
View getPostsReduxAction.js
import axios from 'axios';
export const GET_POSTS_START = 'GET_POSTS_START';
export const GET_POSTS_SUCCESS = 'GET_POSTS_SUCCESS';
export const GET_POSTS_FAIL = 'GET_POSTS_FAIL';
const getPostsStart = () => ({
type: GET_POSTS_START,
});
@abachuk
abachuk / react-file-upload-to-cdn-handler.js
Created Jun 26, 2017
upload files to custom node middleware and CDN, get response back in react.js
View react-file-upload-to-cdn-handler.js
import React, { Component } from 'react';
import axios from 'axios';
class uploadMyFile extends Component {
handleUploadFile = (event) => {
const data = new FormData();
data.append('file', event.target.files[0]);
data.append('name', 'some value user types');
data.append('description', 'some value user types');
// '/files' is your node.js route that triggers our middleware
You can’t perform that action at this time.