Skip to content

Instantly share code, notes, and snippets.

Avatar
😈
--no-verify

Max Belsky mbelsky

😈
--no-verify
View GitHub Profile
View Portal.tsx
import React, {useRef, useEffect} from 'react'
import {createPortal} from 'react-dom'
type PortalProps = {
children: React.ReactNode
}
function Portal({children}: PortalProps): JSX.Element {
const modalContainer = document.body
const modalElementRef = useRef<HTMLDivElement>()
View use-hover-example.js
import { useRef, useState, useEffect } from 'react';
// Usage
function App() {
const [hoverRef, isHovered] = useHover();
return (
<div ref={hoverRef}>
{isHovered ? '😁' : '☹️'}
</div>
View use-hover-alt-example.ts
import {useState, useCallback, useRef} from 'react'
// Hook
const useHover = <T extends HTMLElement>(): [
(node?: T | null) => void,
boolean,
] => {
const [value, setValue] = useState(false)
// Wrap in useCallback so we can use in dependencies below
@mbelsky
mbelsky / ImageRedrawer.m
Last active Apr 4, 2016
Redraw an image for new size
View ImageRedrawer.m
UIImage *image = [[UIImage alloc] initWith: something];
if (image.size.width != kAppIconSize || image.size.height != kAppIconSize) {
CGSize itemSize = CGSizeMake(kAppIconSize, kAppIconSize);
UIGraphicsBeginImageContextWithOptions(itemSize, NO, 0.0f);
CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height);
[image drawInRect:imageRect];
self.appRecord.appIcon = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
@mbelsky
mbelsky / android-custom-res-folder.gradle
Last active Apr 4, 2016
Code to split wide 'res' folder
View android-custom-res-folder.gradle
sourceSets {
main {
res.srcDirs = [
'src/main/res-main',
'src/main/res-screen/about',
'src/main/res-screen/chat',
'src/main/res-screen/event-detail',
'src/main/res-screen/event-list',
'src/main/res-screen/home',
'src/main/res-screen/login',
@mbelsky
mbelsky / adb shell
Last active Apr 7, 2016
Useful 'adb shell' commands
View adb shell
adb shell dumpsys activity | grep -I 'PACKAGE_NAME'
adb shell am start -n PACKAGE_NAME/.PATH_TO_ACTIVITY.ACTIVITY_NAME
# Grant or revoke one or more permissions:
adb shell pm [grant|revoke] <PACKAGE> <PERMISSION>
@mbelsky
mbelsky / .gitignore
Last active Feb 13, 2017
.gitignore file for Objective-C, Swift, xCode 7, CocoaPods
View .gitignore
####
# OS X temporary files that should never be committed
#
# c.f. http://www.westwind.com/reference/os-x/invisibles.html
.DS_Store
# c.f. http://www.westwind.com/reference/os-x/invisibles.html
.Trashes
@mbelsky
mbelsky / android-sdk-setup.sh
Last active Aug 29, 2015 — forked from johnjohndoe/android-sdk-setup.sh
Creating symbolic links in Android SDK folder. After Android-Studio resp. IntelliJ will work with Maven and Gradle.
View android-sdk-setup.sh
#!/bin/bash
# Author: Tobias Preuss
# Version: 2015-03-26
echo "Creating symbolic links in Android SDK folder"
echo "============================================="
echo
if [ -z "$ANDROID_HOME" ] ; then
@mbelsky
mbelsky / android-custom-release-keystore.gradle
Created Jun 25, 2015
Snippet to custom keystore file for release apk file.
View android-custom-release-keystore.gradle
/**
* Create your key store: keytool -genkey -v -keystore release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000
* and after update your build.gradle file.
*/
android {
signingConfigs {
release {
storeFile file("release.keystore")
storePassword "******"
keyAlias "******"
@mbelsky
mbelsky / android-custom-apk-file-name.gradle
Created Jun 25, 2015
Snippet for adding current version value in android apk release file name
View android-custom-apk-file-name.gradle
/**
* Define 'APP_MODULE_NAME' and 'APK_NAME' vars in gradle.properties file.
*/
android {
applicationVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.apk')) {
def fileName = outputFile.name.replace('.apk', "-${versionName}.apk")
fileName = fileName.replace(APP_MODULE_NAME, APK_NAME)