Skip to content

Instantly share code, notes, and snippets.

View mingca's full-sized avatar
🇨🇦

mingca

🇨🇦
View GitHub Profile
#/spec/support/controller_helpers.rb
module ControllerHelpers
def login_devise_user(options = {})
@request.env["devise.mapping"] = Devise.mappings[:user]
user = FactoryGirl.create(:user, options)
sign_in user
user
end
def login_omniauth_user(provider)
#/spec/controllers/home_controller_spec.rb
require 'rails_helper'
describe HomeController do
shared_examples_for "home controller" do
it "should have a current_user" do
expect(subject.current_user).to_not eq(nil)
end
it "should get index" do
@mingca
mingca / accept_hosted.html
Created October 9, 2019 14:17
Authorize.net React Native webview server html
<!DOCTYPE html>
<html>
<head>
<title>Accept</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=320, user-scalable=no">
<% if Accounting.config.gateway == :production %>
<script type="text/javascript" src="https://js.authorize.net/v1/Accept.js" charset="utf-8"></script>
@mingca
mingca / AcceptHoc.js
Created October 9, 2019 14:15
Authorize.net Accept.js React Native
/**
* Accept.js Webview implementation HOC
*
* Inspired by https://gist.github.com/mingca/3bc6e349a80a2957dfdc4b59c7154bec
*/
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import {
ScrollView,
@mingca
mingca / billing.js
Created October 9, 2019 14:12
Authorize.net Accept.js in React app
/* services/billing.js */
/* Convert Accept.js XmlHttpRequest to Promise */
function createPaymentAsync(data) {
return new Promise(resolve => {
window.Accept.dispatchData(data, resolve);
});
}
/* Parse Accept Errors */
# File: app.rb
require 'date'
require 'test/unit'
CITY_ABBREVS = {
'LA' => 'Los Angeles',
'NYC' => 'New York City'
}.freeze
# "Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
# 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
# By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms."
# Instructions:
# Construct a solution using Ruby that could be incorporated into a larger project. Solutions will be evaluated for readability, testability, and extensibility.
# Calculate sum of even-valued terms in fibonacci
class Fibonacci
attr_accessor :limit
@mingca
mingca / WebViewBridge.js
Created May 4, 2018 14:06 — forked from blankg/WebViewBridge.js
Provides a sample implementation for sending and receiving messages to and from the React-Native WebView (using postMessage/onMessage WebView API).
/**
* Created by Guy Blank on 3/9/17.
*
* This is a sample provides an API to send & receive messages to and from the React-Native WebView (using postMessage/onMessage WebView API).
*
* webViewBridge.send('functionToInvoke', {mydata: 'test'}, function(){console.log('success')},function(){console.log('error')});
*
* The API is designed to be similar to the Cordova exec API so migration to it should be almost seamless.
* The API also provides solution to a React-Native WebView bug in iOS which causes sending consecutive postMessage calls to override each other.
*
@mingca
mingca / prefixed-office-properties.md
Created March 29, 2018 15:16 — forked from p3t3r67x0/prefixed-office-properties.md
MS Office prefixed style properties can be used for older versions of MS Excel, MS PowerPoint or MS Word when you want to save a document, presentation, workbook, or worksheet as a web document, or even in older versions for MS Outlook.

MS Office prefixed style properties

mso-ansi-font-size

Note: Office only

mso-ansi-font-size: large | larger | <length> | medium | <percentage> | small | smaller | x-large | x-small | xx-large | xx-small
/*
Flatten Array - exactly same with Ruby's Array#flatten
Example:
flatten([[1, 2, 3], [4, 5]]); // [1, 2, 3, 4, 5]
*/
function flatten(arr) {
return arr.reduce(function (flat, toFlatten) {
return flat.concat(Array.isArray(toFlatten) ? flatten(toFlatten) : toFlatten);
}, []);
}