Skip to content

Instantly share code, notes, and snippets.

View stomita's full-sized avatar

Shinichi Tomita stomita

View GitHub Profile
/*global sforce:true */
(function() {
function loadScript(url, callback) {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
if (callback) {
script.onload = callback;
script.onreadystatechange = function() {
@stomita
stomita / S3FileList.page
Last active January 28, 2023 05:13
List S3 files in a bucket, using AWS JavaScript SDK with SAML assertion
<apex:page showHeader="false"
standardStylesheets="false"
sidebar="false"
contentType="text/html"
applyBodyTag="false"
applyHtmlTag="false"
cache="true"
docType="html-5.0">
<html>
<head>
@stomita
stomita / SimpleSalesforceConnection.js
Created May 25, 2011 08:40
A Google Apps Script, which simply connects and fetches data from Salesforce RESTful API with OAuth authentication.
/**
* Connect and fetch Salesforce data via OAuth
*/
function queryDataFromSalesforce() {
// Read OAuth consumer key / secret of this client app from script properties,
// which can be issued from Salesforce's remote access setting in advance.
var sfConsumerKey = ScriptProperties.getProperty("sfConsumerKey");
var sfConsumerSecret = ScriptProperties.getProperty("sfConsumerSecret");
if (!sfConsumerKey || !sfConsumerSecret) {
Browser.msgBox("Register Salesforce OAuth Consumer Key and Secret in Script Properties");
@stomita
stomita / cors-config.xml
Created December 24, 2013 07:43
S3 CORS configuration sample
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>DELETE</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
{
"presets": [
["@babel/env", {
"targets": { "esmodules": true }
}]
]
}
@stomita
stomita / index.ts
Last active February 21, 2019 08:52
ScanSnap Home(Mac)で読み取った名刺情報を名刺画像ごとSalesforceへ登録する(TypeScript)
import fs from 'fs';
import os from 'os';
import path from 'path';
import sqlite3 from 'sqlite3';
import jsforce, { Connection } from 'jsforce';
const SCANSNAP_DB_DIR = path.join(os.homedir(), '/Library/Application Support/PFU/ScanSnap Home/Managed/');
const SCANSNAP_FILE_DIR = path.join(os.homedir(), '/Documents/ScanSnapHome.localized');
const SCANSNAP_DB_FILE = path.join(SCANSNAP_DB_DIR, 'ScanSnapHome.sqlite');
const TIMESTAMP_FILE = '.timestamp';
@stomita
stomita / custom-hook-creator.js
Last active November 2, 2018 09:29
This is a proposal of `createStateHook`, in order to eliminate call order magic and top-level restriction
import { createStateHook } from 'react';
export function createFormInputHook() {
const useValueState = createStateHook();
return (initialValue) => {
const [value, setValue] = useValueState(initialValue);
function onHandleChange(e) {
setValue(e.target.value);
}
return { value, onChange: onHandleChange };
@stomita
stomita / legacy-context.js
Last active October 16, 2018 08:08
Create React's new context API style component with legacy context
/* @flow */
import EventEmitter from 'events';
import React, { type Node, type ComponentType } from 'react';
import PropTypes from 'prop-types';
/**
* Mimics new context API using legacy context
*/
type LegacyContextProvider<T> = ComponentType<{ value: T, children: Node }>;
@stomita
stomita / index.js
Created October 13, 2018 02:18
Legacy & New Context API / shouldUpdate is ignored in Function Component
/**
*
*/
import React, { createContext } from 'react';
import { createStore } from 'redux';
import { connect, Provider } from 'react-redux';
import { render } from 'react-dom';
import { compose, lifecycle, withStateHandlers, shouldUpdate } from 'recompose';
@stomita
stomita / flowtest.js
Last active February 16, 2017 10:15
Flowtypeの不可解な挙動
/* @flow */
type NMap = { [key:string]: number }
// これは当然だめ
const map1: NMap = {
a: 1,
b: 2,
c: 'a',
};