Skip to content

Instantly share code, notes, and snippets.

View sanitize-wysiwyg-paste.js
import sanitizeHTML from 'sanitize-html'
const wysiwygSel = '.wysiwyg'
const allowedTags = [
'b',
'i',
'u',
'br',
]
@danielrw7
danielrw7 / NumberInput.vue
Last active Jun 6, 2019
Vue NumberInput component allowing for shift + arrow key to jump up and down by a specified amount
View NumberInput.vue
<template>
<input type="number" @keydown.native="onKeydown" :value="value" @input="onInput" :min="min" :max="max" :step="step" v-bind="$attrs" />
</template>
<script>
export default {
name: 'NumberInput',
props: {
value: {
type: Number,
View roundPadded.js
function roundPadded(n, d = 0) {
const div = Math.pow(10, d)
let res = (Math.round(n * div) / div).toString().split('.')
const whole = res[0]
if (d <= 0) {
return whole
}
let dec = res[1] || ''
if (d > 0 && dec.length < d) {
dec += '0'.repeat(d - dec.length)
View jsonToCsv.js
function jsonToCsv(headers, rows, rowSep="\r\n") {
function escape(value) {
return `"${value.toString().replace('"', '""')}"`
}
function row(values) {
return values.map(escape).join(',').replace(/(,"")+$/, '')
}
return row(headers) + rowSep + rows.map(row => {
return headers.map(header => row[header] || '')
}).map(row).join(rowSep)
@danielrw7
danielrw7 / Ownable.sol
Created Jun 16, 2017
First draft of a generic tradeable contract
View Ownable.sol
pragma solidity ^0.4.11;
/**
* @title Ownable
* @dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions".
*/
contract Ownable {
address public owner;
@danielrw7
danielrw7 / SafeQuery.php
Last active Jun 8, 2017
PDO safe query generation
View SafeQuery.php
<?php
// Args:
// SafeQuery::safe_query($table, $select_fields = array("*"), $where = array(), $order_by = array(), $limit = array(0,100))
$ops = array(
"equals" => array("="),
"not_equals" => array("!="),
"greater_than" => array(">"),
"greater_than_or_equal" => array(">="),
"less_than" => array("<"),
View jquery.overlay.js
var overlay = {
el: false,
class: 'overlay',
show: function(clickCallback) {
this.el.show()
if (clickCallback && typeof clickCallback == "function") {
this.el.off('click').click(clickCallback)
}
},
hide: function() {
View toggle-fullscreen.jquery.js
$(function() {
$.fn.toggleFullscreen = function() {
var elem = this[0];
if (!document.fullscreenElement && !document.mozFullScreenElement && !document.webkitFullscreenElement && !document.msFullscreenElement ) {
if (elem.requestFullscreen) {
elem.requestFullscreen();
} else if (elem.msRequestFullscreen) {
elem.msRequestFullscreen();
} else if (elem.mozRequestFullScreen) {
elem.mozRequestFullScreen();
View spreadsheet_to_sql.php
<?php
function convert_spreadsheet_rows_to_sql($table_name, $row_mappings = array(), $rows = array(), $start_row = 2) {
$mappings = array();
$fields = array();
foreach ($row_mappings as $ind => $field) {
if ($field) {
$mappings[] = $ind;
$fields[] = $field;
}
}
You can’t perform that action at this time.