Skip to content

Instantly share code, notes, and snippets.

View lil12t's full-sized avatar
🎖️

Lilian lil12t

🎖️
View GitHub Profile
@lil12t
lil12t / base64.ts
Created December 26, 2020 09:41
Get base64 from File | convert file to base64
export const getBase64 = (file: File): Promise<string> =>
new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = function (): void {
resolve(reader.result?.toString());
};
reader.onerror = function (error): void {
reject(error);
};
@lil12t
lil12t / barcode-perfomance.tsx
Last active December 26, 2020 18:34
[react-native-camera] [android] Slow barcode read fix
/**
* Boosts up barcode read performance on Android
*/
const RNCameraProps: RNCameraProps = {};
if (Platform.OS === OS.IOS) {
RNCameraProps.onBarCodeRead = ({ data }) => {
console.log(data);
};
} else {
@lil12t
lil12t / eraseDisk.sh
Last active December 27, 2020 15:17
Hard format usb drive on mac OS
# It formats disk2 in format FAT32
# In order to check your disk name run: diskutil list
sudo diskutil eraseDisk FAT32 MYSD MBRFormat /dev/disk2
@lil12t
lil12t / select-latest.sql
Last active December 31, 2020 11:05
Select latest items grouped by status (non duplicates)
/* OUTPUTS ALL STATUSES WITH LATEST ITEM, 4 STATUSES = 4 ITEMS IN OUTPUT */
SELECT m1.*
FROM stats m1
LEFT JOIN stats m2
ON (m1.status = m2.status AND m1.created_at < m2.created_at)
WHERE m2.id IS NULL;
@lil12t
lil12t / alreadySearched.tsx
Created January 2, 2021 12:19
Wrods search history filter
const alreadySearched = useMemo(
() =>
[...history]
.slice(0, MAX_ITEMS_PER_PAGE)
.filter((element) =>
items.some((item) =>
item.name.toLowerCase().includes(element.toLowerCase()),
),
),
[history, items],
@lil12t
lil12t / objectNotEmpty.ts
Created January 10, 2021 22:05
object has at least one property filled with data
const hasValues = Object.values({
...sample,
}).some((val) => !isEmpty(val));
@lil12t
lil12t / jest-mock-date.ts
Last active January 13, 2021 17:23
jest mock new Date()
/**
* Mocks new Date() in jest
*/
const mockDate: any = new Date(1466424490000);
const spy = jest.spyOn(global, 'Date').mockImplementation(() => mockDate);
expect(YourTestResult.date).toEqual(new Date(1466424490000));
spy.mockRestore();