Skip to content

Instantly share code, notes, and snippets.

View jespr's full-sized avatar
😃

Jesper Christiansen jespr

😃
  • San Francisco, California
View GitHub Profile
@jespr
jespr / dayOffset.js
Created December 3, 2019 06:11
Return the day of the week given an offset in days
// dayOffset("Wednesday", 4)
// => "Sunday"
const dayOffset = (day, offset) => {
const days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
if (days.indexOf(day) === -1) {
return "😭 Not a valid day, dummy!";
}
@jespr
jespr / validation.js
Created February 15, 2019 06:57
Javascript form validation
<script>
document.addEventListener("DOMContentLoaded", function () {
var formSelector = 'form';
document.querySelector(formSelector).addEventListener("submit", function (e) {
var isValid = true;
// Match all fields that have aria-required="true"
var requiredFields = document.querySelectorAll("[aria-required='true']")
// Loop over all required fields
<a href="http://facebook.con" target="_blank">Test</a>
@jespr
jespr / spaces.rb
Created February 2, 2015 22:27
Spaces
# Usage: ruby spaces.rb haha 2
# => "h a h a"
input, spaces = ARGV[0], ARGV[1]
output = ""
input.split('').each do |char|
output << char
output << " " * spaces.to_i
end

Keybase proof

I hereby claim:

  • I am jespr on github.
  • I am jespr (https://keybase.io/jespr) on keybase.
  • I have a public key whose fingerprint is 7448 C110 1AA3 3440 4D7E A01D 0A7E 6752 334E 65AF

To claim this, I am signing this object:

Pizza med ananas og koriander Jamie Oliver Style
@jespr
jespr / hashrocket
Created October 19, 2012 08:04 — forked from libo/hashrocket
No hashrocket pre-commit
#!/usr/bin/env ruby
# Inspiration from:
# http://jish.github.com/pre-commit/
# https://gist.github.com/2711625
messages = []
HASHROCKET_PATTERN = ":[@$_A-Za-z][_A-Za-z0-9]*[=!?]? *=> *"
# Find the names of all the filenames that have been (A)dded (C)opied or (M)odified
@jespr
jespr / gist:1376594
Created November 18, 2011 14:31
Sublime Text 2 - Insert #{} when pressing #
{ "keys": ["#"], "command": "insert_snippet", "args": {"contents": "#{$0}"}, "context":
[
{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^(\"$)", "match_all": true }
]
},
{ "keys": ["#"], "command": "insert_snippet", "args": {"contents": "#{${0:$SELECTION}}"}, "context":
[
{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },