Skip to content

Instantly share code, notes, and snippets.

View App.js
import { StatusBar } from 'expo-status-bar'
import React, { useCallback, useEffect, useState } from 'react'
import {
Image,
Pressable,
SafeAreaView,
StyleSheet,
Text,
useWindowDimensions,
View,
@ahmedam55
ahmedam55 / index.html
Last active Apr 25, 2019
Service Worker: Serve from Cache, then revalidate the Cache After Specific Time
View index.html
<html>
<head>
<link rel="stylesheet" href="/style.css">
</head>
<body>
PWA: Stale-while-revalidate: xx
<script src="/script.js"></script>
</body>
</html>
@ahmedam55
ahmedam55 / script.sh
Created Apr 21, 2019
Convert Video to Gif
View script.sh
function gif {
ffmpeg -y -i $1 -vf fps=10,scale=${2:-1280}:-1:flags=lanczos,palettegen palette.png
ffmpeg -i $1 -i palette.png -filter_complex "fps=10,scale=${2:-1280}:-1:flags=lanczos[x];[x][1:v]paletteuse" output.gif
rm palette.png
}
@ahmedam55
ahmedam55 / index.html
Last active Apr 25, 2019
Service Worker: Cache then Update Strategy
View index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Service Worker</title>
<link rel="stylesheet" href="/style.css">
</head>
<body>
@ahmedam55
ahmedam55 / googleImage.sh
Created Nov 27, 2018
Embedding or sharing an image or photo uploaded to Google Drive.
View googleImage.sh
# Usage: googleImage https://drive.google.com/file/d/1ohKYjS7FxgkHCqdhP5gpYPMJN8xueqF2/view?usp=sharing
# Output: https://doc-0c-a4-docs.googleusercontent.com/docs/securesc/ha0ro937gcuc7l7deffksulhg5h7mbp1/50g94rphugajflevka9unjmgidqmudio/1543312800000/16295291601680688896/*/1ohKYjS7FxgkHCqdhP5gpYPMJN8xueqF2
function googleImage {
# Replace the parts around sharable link of google drive to extract the fileId
local fileId=$(echo 'https://drive.google.com/file/d/1ohKYjS7FxgkHCqdhP5gpYPMJN8xueqF2/view?usp=sharing' | sed 's/https:\/\/drive.google.com\/file\/d\///g' | sed 's/\/view\?usp=sharing//g')
# Prepend the exportable link
local url="https://docs.google.com/uc?id=$fileId"
# Get public generated url
local publicUrl=$(curl -Ls -o /dev/null -w %{url_effective} $url)
View pip.js
pipButtonElement.addEventListener('click', async function() {
pipButtonElement.disabled = true;
await videoElement.requestPictureInPicture();
pipButtonElement.disabled = false;
});
View index.html
<video id="videoElement" src="https://example.com/file.mp4"></video>
<button id="pipButtonElement">Open Picture in Picture mode</button>
@ahmedam55
ahmedam55 / style.css
Last active Jul 7, 2019
Prevent scroll on IOS
View style.css
.no-scroll {
overflow: hidden;
position: fixed;
}
View index.js
import React, { Component } from "react";
import {
AppRegistry,
StyleSheet,
Text,
View,
FlatList,
AsyncStorage,
Button,
TextInput,
View index.js
import { h, render, Component } from 'preact';
class App extends Component {
render(props, { data }) {
return (<h1>Hello World!</h1>)
}
}