Skip to content

Instantly share code, notes, and snippets.

View dmurawsky's full-sized avatar

Daniel Murawsky dmurawsky

View GitHub Profile
@dmurawsky
dmurawsky / example.md
Last active August 22, 2019 18:57 — forked from gabeklein/example.md
class ActionSequence extends React.Component {
  state={
    remaining = 60,
    surname = "bond"
  }

  componentDidMount(){
    this.timer = 
      setInterval(() => {
import firebase from "firebase/app";
import "firebase/database";
export const withFirebase = comp => {
comp.componentDidMount = () => {
if (!firebase.apps.length) {
firebase.initializeApp({
apiKey: "",
authDomain: "",
databaseURL: "",
@dmurawsky
dmurawsky / bulkImageDownload.js
Created February 3, 2020 17:56
Deno bulk image downloader
// To Run:
// deno run --allow-read --allow-net --allow-write ./bulkImageDownload.ts
const ROOT_URL = 'https://www.example.com/images/';
const imgs = [ 'image1.jpg', 'image2.jpg', 'image3.jpg', 'image4.jpg' ];
const init = () =>
Promise.all(
imgs.map((fileName) =>
fetch(ROOT_URL + fileName).then((resp) => resp.arrayBuffer()).then((buffer) => {
@dmurawsky
dmurawsky / delete_tags_in_bucket.sh
Created May 22, 2020 17:41
AWS CLI delete all tags in a bucket
# Make sure you have aws installed: https://docs.aws.amazon.com/cli/latest/userguide/install-macos.html
# Make sure you have jq installed: https://github.com/stedolan/jq/wiki/Installation
BUCKET=my-s3-bucket
PREFIX=path/to/objects
PROFILE=default
aws s3api list-objects --bucket $BUCKET --prefix $PREFIX --profile $PROFILE \ # List objects in bucket and prefix
| jq ".Contents" \ # Get the array of ojbects
| jq "map(\"aws s3api delete-object-tagging --profile ${PROFILE} --bucket ${BUCKET} --key \" + .Key)" \ # Create a delete-object-tagging command for each object
@dmurawsky
dmurawsky / pattern.js
Created May 27, 2020 16:23
The pattern of the universe
// Usage: Run the below code in your termainal by either running node and copying the code into the REPL or by saving the code to a file and running node pattern.js
// It will output a consistent pattern no matter how high you count.
// Change 1000 to a higher number to test it
let number = 1;
while (number < 1000) {
next = number + 1;
let reduce = number * next + "";
while (reduce.length > 1) {
@dmurawsky
dmurawsky / firebaseTwilioLambda.js
Last active June 13, 2020 20:42
Helper functions for Firebase and Twilio on Lambda
const axios = require("axios");
const client = require("twilio")(process.env.TWILIO_ACCOUNT_SID, process.env.TWILIO_AUTH_TOKEN);
const getDateObj = () => {
const date = new Date();
const hour = date.getHours();
const d = date.getDate();
const m = date.getMonth() + 1;
const y = date.getFullYear();
return { hour, date: `${y}-${m < 10 ? "0" + m : m}-${d < 10 ? "0" + d : d}` };
@dmurawsky
dmurawsky / printful.js
Created July 2, 2020 16:14
Place an order for a printful item
const Axios = require('axios')
Axios({
method: 'POST',
headers: {
Authorization: 'Basic thisisyourbase64authtoken',
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
},
data: JSON.stringify({
recipient: {
@dmurawsky
dmurawsky / getChromeVersion.js
Created September 30, 2021 18:34
Get Chrome/Chromium version and alert
const getChromeVersion = () => {
const raw = navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./)
return raw ? parseInt(raw[2], 10) : false
}
if (getChromeVersion() < 93) {
alert('We recommend you use a Chrome browser version 93 or greater otherwise you may experience degraded service.')
}
export const saveLiveSwitchRecording = async (
recordingId: string,
channelId: string,
fileName: string,
type: "video" | "audio"
) => {
const file = makeLiveSwitchRecordingFile(recordingId, channelId, fileName);
const format = fileName.substring(fileName.indexOf(".") + 1);
const writeStream = file.createWriteStream({
metadata: {
@dmurawsky
dmurawsky / firebase8.ts
Last active October 9, 2021 02:34
Example of Firebase v9 database functions vs Firebase v8
import firebase from "firebase/app";
import "firebase/database";
export const onceValue = <T>(path: string): Promise<Nullable<T>> =>
firebase
.database()
.ref(path)
.once("value")
.then((snap) => snap.val());
export const firebaseUpdate = (path: string, updateObj: Object) => firebase.database().ref(path).update(updateObj);