Skip to content

Instantly share code, notes, and snippets.

View steffenz's full-sized avatar
🏠
127.0.0.1

Steffen Martinsen steffenz

🏠
127.0.0.1
  • Oslo, Norway
View GitHub Profile
@steffenz
steffenz / snapchat-memories.js
Last active April 4, 2022 11:33
Download all Snapchat Memories (Node)
/*
1. Go to https://accounts.snapchat.com/ and request download of your data.
2. Download zip-file (when ready) and locate json/memories_history.json
3. Create a new folder with this script and the memories_history.json file
4. Install node-fetch; npm install node-fetch@^2.6.6 (using older version to avoid having to import as module)
5. Run the script.
Files will be prefixed with the date and a unique ID (from Snapchat) to avoid overwriting (see more details below).
This script was originally inspired by this StackOverflow question (but has since diverged greatly); https://stackoverflow.com/questions/61058637/snapchat-download-all-memories-at-once
@steffenz
steffenz / json-regex-vscode
Created December 8, 2019 11:44
Search/replace Regex (used with VSCode)
(?<="value": ")[^"]+(?=")
https://stackoverflow.com/questions/43577528/visual-studio-code-search-and-replace-with-regular-expressions
https://regex101.com/r/7J06ki/1
@steffenz
steffenz / wp-react-plugin.php
Created May 7, 2019 07:19
Embedding React application inside a WordPress plugin
<?php
$scripts = preg_grep('~\.(js)$~', scandir(__DIR__. '/../react-frontend/build/static/js'));
foreach($scripts as $script){
wp_enqueue_script("react-{$script}", plugin_dir_url( __FILE__ ). "./../react-frontend/build/static/js/{$script}");
}
echo "<div id="root">Enabled JavaScript to see this page</div>";
?>
@steffenz
steffenz / HookedMaps.js
Last active March 19, 2019 15:05
React Google Maps with Hooks. This will be moved into a NPM package at one point..
import React, { useState, useEffect } from 'react';
export default ({ id = null, timeout = 15000, children, onReady, apiKey }) => {
/* To-do: Add support for auto generated id */
// const [ stateId ] = useState((id === null) ? `gmap-${new Date().valueOf()}` : id);
useEffect(() => {
let mapsUrl = `https://maps.google.com/maps/api/js?key=${apiKey}`;
let allBodyScripts = Array.from(document.getElementsByTagName('script'));
let exists = allBodyScripts.find(item => item.src === mapsUrl);
if(!exists){
<?php
/*
Plugin Name: Netlify Build
Description: Runs a Netlify build when saving
Author: Steffen Martinsen
Version: 0.0.1
*/
defined('ABSPATH') or die();
@steffenz
steffenz / ffmpeg-and-webp.sh
Last active February 6, 2019 11:33
Common commands for converting images, photos and videos for web.
# Converts video (2 pass) with 15 fps @ 500kbs without audio (ideal for web) - http://trac.ffmpeg.org/wiki/Encode/VP9
# Run both lines
ffmpeg -i input.mp4 -framerate 15 -c:v libvpx-vp9 -b:v 500k -pass 1 -an -f webm /dev/null && \
ffmpeg -i input.mp4 -framerate 15 -c:v libvpx-vp9 -b:v 500k -pass 2 -an output.webm
# Converts audio to OGG (96 kb/s) https://superuser.com/questions/1121334/how-to-use-ffmpeg-to-encode-ogg-audio-files
ffmpeg -i input.aif -c:a libvorbis -b:a 96k output.ogg
#Converts audio to MP3 (96 kb/s) https://trac.ffmpeg.org/wiki/Encode/MP3
ffmpeg -i input.aif -c:a libmp3lame -b:a 96k output.mp3