Skip to content

Instantly share code, notes, and snippets.

View giioohbernini's full-sized avatar
😎
Stay foolish, stay hungry.

Giovanni Bernini giioohbernini

😎
Stay foolish, stay hungry.
View GitHub Profile
@giioohbernini
giioohbernini / resizeImage.js
Created February 5, 2021 18:21
Client-side image resizer with Javascript
const scaleCanvas = (canvas, scale) => {
const scaledCanvas = document.createElement('canvas')
scaledCanvas.width = canvas.width * scale
scaledCanvas.height = canvas.height * scale
scaledCanvas
.getContext('2d')
.drawImage(canvas, 0, 0, scaledCanvas.width, scaledCanvas.height)
return scaledCanvas
@giioohbernini
giioohbernini / patch_apk_for_sniffing.md
Created January 20, 2021 15:28 — forked from unoexperto/patch_apk_for_sniffing.md
How to patch Android app to sniff its HTTPS traffic with self-signed certificate

How to patch Android app to sniff its HTTPS traffic with self-signed certificate

  • Download apktool from https://ibotpeaches.github.io/Apktool/
  • Unpack apk file: java -jar /home/expert/work/tools/apktool.jar d [email protected]
  • Modify AndroidManifest.xml by adding android:networkSecurityConfig="@xml/network_security_config" attribute to application element.
  • Create file /res/xml/network_security_config.xml with following content:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config>
@giioohbernini
giioohbernini / useWebview.js
Last active July 28, 2020 17:05
Web to native #7
import messageEvents from '~/utils/messageEvents'
//...
const handleOnMessage = event => {
const value = event.nativeEvent.data
const parsedValue = JSON.parse(value)
messageEvents({ ...parsedValue, setCurrentUrl, setCanGoBack, ...props })
}
@giioohbernini
giioohbernini / Main.js
Created July 28, 2020 17:02
Web to native #6
// ....
<WebView
source={{ uri: URI }}
onMessage={handleOnMessage}
onNavigationStateChange={handleNavigationChange}
ref={handleRef}
onLoadStart={handleSpinner(true)}
onLoad={handleSpinner(false)}
/>
@giioohbernini
giioohbernini / postMessage.js
Last active July 28, 2020 17:00
Web to native #5
const postMessage = data => {
/* Esse trecho verifica se o método existe.
Quando estivermos rodando no browser ele não irá existir. */
const hasRNPostMessage = window && window.ReactNativeWebView && window.ReactNativeWebView.postMessage
if (hasRNPostMessage) {
const dataStringify = JSON.stringify(data)
window.ReactNativeWebView.postMessage(dataStringify)
}
@giioohbernini
giioohbernini / Root.js
Created July 28, 2020 15:20
Web to native #4
import React, {useEffect} from 'react'
import {Link, useLocation} from 'react-router-dom'
import postMessage from './utils/postMessage.js'
const Root = () => {
const location = useLocation();
useEffect(() => {
const data = {
eventName: 'routeChange',
@giioohbernini
giioohbernini / About.js
Created July 28, 2020 15:16
Web to native #3
import React from 'react'
import isApp from 'utils/isApp'
const welcomeType = isApp
? 'Your app about page'
: 'Your web about page'
const About = () => {
return (
<div>
@giioohbernini
giioohbernini / Home.js
Created July 28, 2020 14:02
Web no native #2
import React from 'react'
import isApp from 'utils/isApp'
const welcomeType = isApp
? 'Your app home page'
: 'Your web home page'
const Home = () => {
return (
<div>
@giioohbernini
giioohbernini / App.js
Last active July 28, 2020 13:55
Web to native #1
import React from 'react'
import {
BrowserRouter as Router,
Route,
} from 'react-router-dom'
import Root from './Root'
import Home from './pages/Home'
import About from './pages/About'
const AppRouter = () => {