Skip to content

Instantly share code, notes, and snippets.

View benediktvaldez's full-sized avatar
🦸
hi!

Benedikt D Valdez benediktvaldez

🦸
hi!
View GitHub Profile
@kerimdzhanov
kerimdzhanov / random.js
Last active June 25, 2024 19:41
JavaScript: get a random number from a specific range
/**
* Get a random floating point number between `min` and `max`.
*
* @param {number} min - min number
* @param {number} max - max number
* @return {number} a random floating point number
*/
function getRandomFloat(min, max) {
return Math.random() * (max - min) + min;
}
@rememberlenny
rememberlenny / vanilla.js
Last active April 21, 2021 21:30
How to post to Google docs using a jQuery ajax POST request
// url is the link for the form view page
// data is the name attribute of the field
$.ajax({
url: "https://docs.google.com/forms/d/1iqMixtVq4O0AFvYCZHbGerigi1G5Qb3XthXZX9VpNtk/formResponse",
data: { "entry.1679407376": field1},
type: "POST",
dataType: "xml",
statusCode: {
@maranomynet
maranomynet / isValidKennitala.js
Created February 19, 2018 23:23
Simple JavaScript module to validate Icelandic kennitalas
export default function isValidKennitala(kt) {
// Trim and remove optional "-" or " " separators
kt = kt.trim().replace(/\s|-/, '');
// Alternatively only allow separator as 7th character
// kt = kt.replace(/^(.{6})[\s-]/, '$1');
// Must be 10 digits, ending in either 0 or 9 (note Y2.1k problem!)
if ( kt.length !== 10 && !/^\d{9}[90]$/.test(kt) ) {
return false;
}
@jincod
jincod / bitbucket-pipelines.yml
Created October 6, 2018 15:52
Docker deployment using Bitbucket Pipelines and Heroku
pipelines:
default:
- step:
name: build and publish docker image
services:
- docker
caches:
- docker
script:
- docker build -t $APP_NAME .
@barbogast
barbogast / schemaTypes.ts
Created May 18, 2020 15:00
Typescript Definitions for Sanity schemas
import { ReactElement } from 'react'
import { ReactComponentLike } from 'prop-types'
type Meta = {
parent: { [key: string]: any }
path: string[]
document: { [key: string]: any }
}
type CustomRuleCallback = (field: any, meta: Meta) => true | string | Promise<true | string>