Skip to content

Instantly share code, notes, and snippets.

View hadrysmateusz's full-sized avatar
🎯
Focusing

Mateusz Hadryś hadrysmateusz

🎯
Focusing
View GitHub Profile
@hadrysmateusz
hadrysmateusz / Markdium-TypeScript.ts
Created January 3, 2020 01:12
Markdium-Hello Markdium!
let foo = 'bar'
/**
Don't worry about the code block, it will be saved as a gist with right language format, and auto embed to your post.
**/
@hadrysmateusz
hadrysmateusz / Markdium-Diff.diff
Created January 3, 2020 01:12
Markdium-Hello Markdium!
public class Hello1
{
public static void Main()
{
- System.Console.WriteLine("Hello, World!");
+ System.Console.WriteLine("Rock all night long!");
}
}
@hadrysmateusz
hadrysmateusz / Markdium-javascript.js
Created January 3, 2020 01:25
Markdium-Files in Client-Side JS: Ultimate Guide to Using Files in Web Applications
let a = "asdf";
@hadrysmateusz
hadrysmateusz / Markdium-javascript.js
Created January 3, 2020 01:39
Markdium-Files in Client-Side JS: Ultimate Guide to Using Files in Web Applications
const inputElement = document.getElementById("inputElement")
inputElement.onchange = (e) => {
const file = inputElement.files[0]
if (!file) return
const reader = new FileReader()
reader.onload = (e) => {
// e.target points to the reader
const textContent = e.target.result
console.log(`The content of ${file.name} is ${textContent}`)
@hadrysmateusz
hadrysmateusz / Markdium-javascript.js
Created January 3, 2020 01:39
Markdium-Files in Client-Side JS: Ultimate Guide to Using Files in Web Applications
// get a reference to the inputElement in any way you choose
const inputElement = document.getElementById("inputElement")
// get the value once
inputElement.files[0]
// get the value every time the user selects a new file
inputElement.addEventListener("change", (e) => {
// e.target points to the input element
const selectedFile = e.target.files[0]
@hadrysmateusz
hadrysmateusz / Markdium-javascript.js
Created January 3, 2020 01:39
Markdium-Files in Client-Side JS: Ultimate Guide to Using Files in Web Applications
const file = new File([blob], "fileName", {type: blob.type})
const blob = new Blob([file], {type: file.type})
@hadrysmateusz
hadrysmateusz / Markdium-javascript.js
Created January 3, 2020 01:39
Markdium-Files in Client-Side JS: Ultimate Guide to Using Files in Web Applications
// using promise.then()
file.text().then(text => /* do something */);
// using async/await
const text = await file.text();
@hadrysmateusz
hadrysmateusz / Markdium-javascript.js
Created January 3, 2020 01:39
Markdium-Files in Client-Side JS: Ultimate Guide to Using Files in Web Applications
const reader = new FileReader()
// readyState is 0, result is null
reader.onload = () => {
// readyState is 2, result is the file's content
}
reader.onerror = () => {
// readyState is 2, result is null
}
// readyState is 0, result is null
reader.readAsText(file)
@hadrysmateusz
hadrysmateusz / Markdium-javascript.js
Created January 3, 2020 01:39
Markdium-Files in Client-Side JS: Ultimate Guide to Using Files in Web Applications
// assuming that processImage and processText are functions
if (file.type.startsWith('image/')) {
reader.onload = processImage
reader.readAsDataURL(file)
} else if (file.type.startsWith('text/')) {
reader.onload = processText
reader.readAsText(file)
}
@hadrysmateusz
hadrysmateusz / Markdium-HTML.html
Created January 3, 2020 01:39
Markdium-Files in Client-Side JS: Ultimate Guide to Using Files in Web Applications
<input type="file" id="inputElement" />