Skip to content

Instantly share code, notes, and snippets.

View magician11's full-sized avatar

A magician11

  • Golightly+
  • New Zealand
View GitHub Profile
@magician11
magician11 / decoder.js
Created January 12, 2019 19:44
How to edit HTML game files
/*
This will take a .save game file, decode it into its JSON form,
and then save it to game-data.json
*/
const fs = require('fs');
const LZString = require('lz-string');
if (process.argv.length === 3) {
try {
const encodedData = fs.readFileSync(process.argv[2], 'utf8');
@magician11
magician11 / robots.txt.njk
Created September 10, 2023 20:33
sitemap.xml and robots.txt for 11ty (Eleventy)
---
eleventyExcludeFromCollections: true
eleventyComputed:
permalink: "{{ site.robots }}"
---
Sitemap: {{ site.baseUrl + site.siteMap }}
User-agent: *
Disallow:
@magician11
magician11 / chat.py
Created November 6, 2023 20:12
How to create a chat app running locally on a laptop using a Hugging Face model
import time
from transformers import pipeline, Conversation
model_name = "facebook/blenderbot-400M-distill"
start = time.time()
converse = pipeline("conversational", model=model_name)
print(f"Model loaded. Time taken: {time.time() - start} seconds")
conversation = Conversation()
@magician11
magician11 / sort-by-custom-metafield.html
Last active October 8, 2023 15:07
How to sort a collection in Shopify based on a custom metafield.
<!--
This code displays the dropdown for the options to sort from.
Adapted from https://gist.github.com/carolineschnapp/11352987
It will be inserted on every collections page. Probably in a snippet called something like collection-sorting.liquid
-->
<div class="form-horizontal">
<label for="SortBy" class="uppercase">{{ 'collections.sorting.title' | t }}&nbsp;</label>
<select name="SortBy" id="SortBy">
@magician11
magician11 / google-url-shortener.js
Last active September 18, 2023 14:39
How to use Request with the Google URL Shortener API.
const request = require('request');
const GOOGLE_API_KEY = 'your api key'; // from https://console.developers.google.com/apis/credentials
const urlToShorten = 'http://www.thelongurltoshorten.com';
const shortenerUrl = `https://www.googleapis.com/urlshortener/v1/url?key=${GOOGLE_API_KEY}`;
const options = {
uri: shortenerUrl,
json: {
longUrl: urlToShorten
@magician11
magician11 / reorder-button.html
Last active August 31, 2023 06:12
How to create a reorder button in Shopify's Liquid
{% for order in customer.orders %}
{% assign reorder_url = "" %}
{% for line_item in order.line_items %}
{% capture reorder_url %}{{ reorder_url | append: line_item.variant_id | append: ':' | append: line_item.quantity | append: ',' }}{% endcapture %}
{% endfor %}
<a href="{{ '/cart/' | append: reorder_url }}" class="button tiny">reorder</a>
{% endfor %}
@magician11
magician11 / elevenlabs.js
Last active August 3, 2023 09:12
Playing audio generated from ElevenLabs in frontend JavaScript
import axios from 'axios';
const playAudio = async ({ text, voiceId }) => {
const response = await axios.post(
`https://api.elevenlabs.io/v1/text-to-speech/${voiceId}`,
{ text },
{
headers: {
'Content-Type': 'application/json',
'xi-api-key': process.env.REACT_APP_ELEVENLABS_API_KEY
@magician11
magician11 / PasswordInput.js
Created July 19, 2023 16:53
PasswordInput component for react-native-paper
import { useState } from 'react';
import { TextInput } from 'react-native-paper';
const PasswordInput = ({ password, setPassword }) => {
const [showPassword, setShowPassword] = useState(false);
return (
<TextInput
label="Password"
secureTextEntry={!showPassword}
@magician11
magician11 / expo-audio.js
Last active July 18, 2023 18:15
How to play a base64 encoded audio file in expo-av
import { View } from 'react-native';
import {
cacheDirectory,
writeAsStringAsync,
EncodingType
} from 'expo-file-system';
import { Audio } from 'expo-av';
import { Button } from 'react-native-paper';
import base64AudioEncodedString from './assets/sounds';
@magician11
magician11 / currency-conversion.html
Last active December 30, 2022 02:57
How To Create Your Own Currency Conversion App
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Currency Conversion</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
crossorigin="anonymous">