Skip to content

Instantly share code, notes, and snippets.

View zeroFruit's full-sized avatar
🎯
Focusing

JooHyung Kim zeroFruit

🎯
Focusing
View GitHub Profile
// MyComponent.js
const renderHeader = (params) => <Header params={ params } />;
class MyComponent extends Component {
static navigationOptions = {
header: ({ navigation }) => renderHeaderWithNavigation(navigation)(renderHeader)
}
componentDidMount() {
@zeroFruit
zeroFruit / helpers.js
Created December 10, 2017 03:20
React, Reducer, Saga helper
/*
Reducer Helper
*/
export function createReqeuestTypes(_base) {
let base = _base;
if (Array.isArray(base)) base = base.join('/');
const res = {};
[REQUEST, SUCCESS, FAILURE]
.forEach(type => res[type] = `${base}_${type}`);
@zeroFruit
zeroFruit / example.js
Created December 28, 2017 15:10 — forked from tomduncalf/example.js
How to upload a local (iOS filesystem) file to S3 using React Native with temporary credentials
/**
* I recently needed to upload a file from the phone's filesystem to S3 using temporary credentials
* (i.e. access key, secret key and session token) issued by an API for a React Native application,
* without the overhead of Base64 encoding the file and passing it over the bridge (as it could be
* several MB big), and wanted to avoid writing native code to do this.
*
* None of the S3 libraries online worked with the temporary credentials, but I figured out a
* solution using the official AWS SDK (which is good, as it supports all the relevant authentication
* out of the box) and the react-native-fetch-blob module, which allows you to upload directly from the
* filesystem with the correct Content-type header (as far as I can tell, React Native's fetch only
@zeroFruit
zeroFruit / rn-fetch-form-data.js
Created January 2, 2018 05:18
react-native fetch form-data
import axios from 'axios';
const SERVER = 'https://...';
const requests = {
...
post: async (rootUrl, route = '', body = {}, config = {}) => {
const response = await axios.post(`${rootUrl}${route}`, body, config);
return getResponse(response);
}
@zeroFruit
zeroFruit / MinHeap.java
Created May 28, 2018 16:12
Min Heap using Generic
/*
* referenced
* 1. http://www.techiedelight.com/min-heap-max-heap-implementation-in-java/
* 2. https://gist.github.com/flexelem/70b120ac9bf2965f419f
* */
class MinHeap<E extends Comparable<E>> {
private ArrayList<E> heap;
MinHeap() {
heap = new ArrayList<>();
@zeroFruit
zeroFruit / channel1.go
Created June 30, 2018 03:53
basic channel
package main
import (
"sync"
"fmt"
)
var wg = sync.WaitGroup{}
func main() {
@zeroFruit
zeroFruit / allGood.js
Created July 5, 2018 09:24
All good & One good
let allGood = true;
proposalResponses.forEach((pr) => {
let oneGood = false;
if (pr.response && pr.response.status === 200) {
oneGood = true;
logger.info('install proposal was good');
} else {
logger.error('install proposal was bad');
}
@zeroFruit
zeroFruit / testnet_btc_example.go
Created July 30, 2020 15:41
Testnet BTC create address, createRawTransaction example
package main
import (
"bytes"
"encoding/hex"
"fmt"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/chaincfg/chainhash"
@zeroFruit
zeroFruit / addr.go
Created October 31, 2020 12:13
Modeling the Internet from the scratch: Link-layer, LAN, Switch - Code snippet
package link
type Addr string
@zeroFruit
zeroFruit / comm.go
Last active October 31, 2020 12:18
Modeling the Internet from the scratch: Link-layer, LAN, Switch - Code snippet: Network Adapter
package na
// Card is abstracted network adapter part to simulate bytes transport on
// physical cable. Node's interface uses this interface to send frame
// between nodes.
type Card interface {
Send(buf []byte, addr string) (time.Time, error)
Recv() <-chan *FrameData
}