Skip to content

Instantly share code, notes, and snippets.

View ShaswatPrabhat's full-sized avatar

Shaswat Prabhat ShaswatPrabhat

View GitHub Profile
@ShaswatPrabhat
ShaswatPrabhat / useAutoScroll.js
Created June 8, 2020 02:12
useAutoScroll hook to enable React-Native screens to scroll to erroneous form fields
import React, { useRef } from 'react';
import { View, Dimensions } from 'react-native';
import util from 'helpers/util';
const useAutoScroll = () => {
const yCoordinates = useRef({});
let scrollRef = null;
const setScrollRef = ref => {
if (ref) scrollRef = ref;
@ShaswatPrabhat
ShaswatPrabhat / SampleForm.js
Created June 8, 2020 02:29
Sample usage of useAutoScroll
import React, { useState, useEffect, useContext } from 'react';
import { View, ScrollView } from 'react-native';
import { Button, TextInput } from 'MyCustomComponents';
import useAutoScroll from 'useAutoScroll';
import { Controller, FormContext, useForm } from 'react-hook-form';
function SampleForm({ navigation }) {
const { setScrollRef, scrollTracker, scrollTo, captureRef } = useAutoScroll();
const useFormObj = useForm({
@ShaswatPrabhat
ShaswatPrabhat / aoc20_day6.py
Created December 6, 2020 06:14
Day 6 solution for AOC 20
answers = open('input_test.txt').read().replace('\r\n', '\n').replace('\n\n', '|').replace('\n', ' ').split('|')
part1 = 0
part2 = 0
for answer in answers:
part1 += len(set(answer.replace(' ', '')))
part2 += len(set.intersection(*map(set, answer.split())))
print(answer, '--->', list(map(set, answer.split())))