Skip to content

Instantly share code, notes, and snippets.

View WeeHorse's full-sized avatar

Benjamin Berglund WeeHorse

View GitHub Profile
@WeeHorse
WeeHorse / index.html
Created April 20, 2023 09:25
send formdata as json
<!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.0">
<title>Document</title>
<script src="script.js" defer></script>
</head>
<body>
npm run test:unit
TEST_RESULT=$?
if [ $TEST_RESULT -eq 0 ]
then echo "Tests passed. Committing..."
else echo "Testing your changes has failed! Commit will be aborted." && exit 1
fi
npm test
TEST_RESULT=$?
if [ $TEST_RESULT -eq 0 ]
then echo "Tests passed. Committing..."
else echo "Testing your changes has failed! Commit will be aborted." && exit 1
fi
@WeeHorse
WeeHorse / array-sorting-and-sub-sorting.js
Created July 11, 2018 09:07 — forked from dfkaye/array-sorting-and-sub-sorting.js
secondary or sub sorting an array in JavaScript
// 29 Sep 2017
// 4 Oct 2017 - add name object example.
// 14 Nov 2017 - pass `a.name, b.name` to `byName()`; rename `test` as `diff`.
// 1 Jan 2018 - made some functions more readable.
// Inspired by post at https://alistapart.com/article/what-i-talk-about-when-i-talk-about-sorting
// which covers an example of sorting by age, but does not ensure items of same age are secondarily
// sorted by name in alphabetical order.
// This snippet shows how to do that whether names are strings or objects with first and last properties.
<!DOCTYPE html>
<html>
<body>
<form method="post">
First name:<br>
<input type="text" name="firstname" value="Mickey">
<br>
Last name:<br>
<input type="text" name="lastname" value="Mouse">
@WeeHorse
WeeHorse / example_my_buildings_data_structure.js
Last active February 10, 2016 10:32
example my buildings data structure
// see it at https://jsbin.com/mejoke/edit?html,js,console,output
var data = [
{
filename:'england',
path: 'england/',
children:[
{
filename:'1920',
path: 'england/1920/' ,
@WeeHorse
WeeHorse / hangman.js
Created February 9, 2016 10:47
Hangman jquery version
// Vi sätter de variabler vi vill ha tillgång till inifrån alla funktioner
var body = $('body');
var displayBox = $('#displayBox');
var bokstavInput = $('#bokstav');
// (tills vidare hårdkodar vi vårt hemliga ord)
var hemligtOrd = 'BRO';
var galgKroppDelar = [];
var doltOrd = [];
var anvandaBokstaver = [];
var maxAntalGissningar;
@WeeHorse
WeeHorse / hangman.js
Last active February 9, 2016 10:48
Hangman native version
// Vi sätter de variabler vi vill ha tillgång till inifrån alla funktioner
// (tills vidare hårdkodar vi vårt hemliga ord)
var hemligtOrd = 'BRO';
var galgKroppDelar = [];
var doltOrd = [];
var anvandaBokstaver = [];
var maxAntalGissningar;
function display(str){
@WeeHorse
WeeHorse / findingPeople.js
Last active February 9, 2016 09:32
WCMS15 Javascript övningsuppgifter 1 vecka 6: Hitta/filtrera personer
// Övningsuppgifter 1 vecka 6:
// Vi har vår data:
// Men lägg till ett par Stockholmare för oss att söka på också:
var list = [
{firstName: 'Benjamin',
lastName: 'Berglund',
age: 46,
city: 'Malmö'},