Skip to content

Instantly share code, notes, and snippets.

View abusedmedia's full-sized avatar

Fabio Franchino abusedmedia

View GitHub Profile
const arr = {{ dataset.data }}
const summ = summarizeProperties(arr, ['name'])
let res = ''
for(let p in summ){
const fp = `The property ${p} can have`
const ps = Array.isArray(summ[p])
? ` the following values: ${summ[p].toString()}.`
: ` values between ${summ[p].min} and ${summ[p].max}.`
const data = {{ dataset.data }}
const openai = {{ openai.data }}
const { sql } = openai || {sql:'SELECT * FROM ?'}
const res = alasql(sql,[data])
return res
@abusedmedia
abusedmedia / summarizeProperties.js
Created April 20, 2024 13:12
Handy function to get some summarization from a js array
window.summarizeProperties = (data, excluded = []) => {
const result = {};
data.forEach(obj => {
for (const key in obj) {
if (excluded.indexOf(key) === -1) {
let value = obj[key];
let valueIsDate = false;
// Check if the value is a date
const distance = (lat1,lon1,lat2,lon2) => {
lon1 = lon1 * Math.PI / 180
lon2 = lon2 * Math.PI / 180
lat1 = lat1 * Math.PI / 180
lat2 = lat2 * Math.PI / 180
let dlon = lon2 - lon1;
let dlat = lat2 - lat1;
let a = Math.pow(Math.sin(dlat / 2), 2) + Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(dlon / 2),2)
@abusedmedia
abusedmedia / ember-sandbox-service.js
Created October 18, 2022 07:46 — forked from devotox/ember-sandbox-service.js
Create A Javascript sandbox to execute custom code without giving access to things like window and outer contextThey still have a `this` object they can use across multiple executions to persist data
import Service from '@ember/service';
const has = () => true;
const { console, WeakMap, Proxy, Symbol } = window;
const get = (target, key) => key === Symbol.unscopables ? undefined : target[key];
export default Service.extend({
@abusedmedia
abusedmedia / example.js
Created October 1, 2021 17:50 — forked from andrei-tofan/example.js
node.js writable buffer stream (pdfkit example)
/**
* Convert PDFDocument to Base64
*/
const PDFDocument = require('pdfkit');
const stream = require('./stream');
// crate document and write stream
let doc = new PDFDocument();
let writeStream = new stream.WritableBufferStream();
col.append('<div class="item" style="flex:'+flex_value_row+';background-color:'+color+';margin-bottom:'+border_bottom+'px;"></div>')
var col = $('<div class="col" style="flex:'+flex_value_col+';"></div>')
function gen(){
$('body').empty()
var number_column = parseInt(Math.random()*6) + 2
for(var i=0; i<number_column; ++i){
var number_rows = parseInt(Math.random()*50) + 5
<script async id="__bs_script__"
src="http://localhost:3000/ browser-sync/ browser-sync-client.js?v=2.18.8 ">
</script>