Skip to content

Instantly share code, notes, and snippets.

@hewrin
hewrin / example_fetch.js
Created May 20, 2018 14:50
Using fetch with React on Rails
function login(formData) {
let header = { "Content-Type": "application/x-www-form-urlencoded" }
return fetch('${USER_API_URL}/login',
{ headers: ReactOnRails.authenticityHeaders(header),
body: formData, method: "POST" })
.then(res => res.status).catch(err => console.error(err)); }
}
import React, { Component } from 'react';
import {
Platform, KeyboardAvoidingView, Modal
} from 'react-native';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import { NavigationActions, StackActions } from 'react-navigation';
import {
bulkUpdate, updateAgentCode,
} from '../actions/bulkParcelUpdate';
import { SHOW_ERROR_SCREEN, SHOW_ERROR_SCREEN_WITH_CUSTOM_MESSAGE, HIDE_ERROR_SCREEN, SHOW_SUCCESS_SCREEN } from '../actions/statusScreen';
const initialState = {
show: false,
errorTitle: '',
errorMessage: '',
success: false
};
export const SHOW_ERROR_SCREEN = 'SHOW_ERROR_SCREEN'
export const SHOW_ERROR_SCREEN_WITH_CUSTOM_MESSAGE = 'SHOW_ERROR_SCREEN_WITH_CUSTOM_MESSAGE'
export const HIDE_ERROR_SCREEN = 'HIDE_ERROR_SCREEN'
export const SHOW_SUCCESS_SCREEN = 'SHOW_SUCCESS_SCREEN'
const showErrorScreen = () => (
{ type: SHOW_ERROR_SCREEN }
)
import { call, put, select } from 'redux-saga/effects';
import Config from 'react-native-config';
import { SHOW_SUCCESS_SCREEN, SHOW_ERROR_SCREEN } from '../../actions/statusScreen';
const bulkParcelUpdate = params => fetch(`${Config.SERVER_URL}/api/v2/agents/parcels`, {
method: 'PATCH',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: `Bearer ${params.authToken}`,
@hewrin
hewrin / svg-convert.sh
Created November 8, 2018 07:31 — forked from zolthan/svg-convert.sh
Convert SVG to PNG @2x @3x
#!/bin/bash
# I made this script to convert SVG icons for an iOS app into PNG.
# The script will create icons in 3 sizes for different screen DPIs.
find . -type f -name "*.svg" | while read f
do
echo '---'
FILENAME="${f%.*}"
echo $FILENAME
@hewrin
hewrin / articleTable.js
Created June 8, 2020 04:55
I'm trying to create an Editable Table, But for some reason the `values` value is empty even though I have set initialValues.
import React, { useEffect, useState, useCallback } from "react"
import "@shopify/polaris/styles.css";
import { AppProvider, Card, ResourceList, ResourceItem, TextField, FormLayout, Filters, Page } from '@shopify/polaris';
import ApolloClient from 'apollo-boost';
import { gql } from "apollo-boost";
import { Formik, Form, Field, FieldArray } from 'formik';
function ArticleTable ({token}) {
const [queryValue, setQueryValue] = useState(null);
const [blogPostList, setblogPostList] = useState([]);
@hewrin
hewrin / shopify_recurring_application_charge_service.rb
Last active June 16, 2020 02:52
Shopify service object for recurring_application_charge_service
class Shopify::RecurringApplicationChargeService
attr_reader :render_hash
def initialize(shop:)
@shop = shop
@shop_country = @shop.address.country
@render_hash = {}
end
def call
@hewrin
hewrin / haravan_recurring_application_charge_service.rb
Created June 16, 2020 02:52
Haravan service object for recurring_application_charge_service
class Haravan::RecurringApplicationChargeService
attr_reader :render_hash
def initialize(plan:, shop:)
@plan = plan
@shop = shop
@redirect_url = ''
@session = nil
end
@hewrin
hewrin / recurring_charges_controller.rb
Created June 16, 2020 03:05
Recurring Charges controller
# frozen_string_literal: true
class Api::V1::RecurringChargesController < Api::V1::BaseController
before_action :set_ecommerce_api_session
def create
plan = Plan.find_by(id: params[:plan_id])
if current_shop.ecom_provider == 'Haravan'
service = Haravan::RecurringApplicationChargeService.new(plan: plan, shop: current_shop)