Skip to content

Instantly share code, notes, and snippets.

View rikyperdana's full-sized avatar
💭
Alhamdulillah

Riky Perdana rikyperdana

💭
Alhamdulillah
View GitHub Profile
@rikyperdana
rikyperdana / mitGenFull.js
Created May 14, 2024 01:23
All minified AutoForm + AutoTable + MitGen
var m,_,afState={arrLen:{},form:{}},{stringify,parse}=JSON,autoForm=opts=>({view:()=>{var withAs=(obj,cb)=>cb(obj),ifit=(obj,cb)=>Boolean(obj)&&cb(obj),ors=array=>array.find(Boolean),ands=array=>array.reduce((a,b)=>a&&b,true),normal=name=>name.replace(/\d/g,'$'),fileData=(key,val)=>{var form=new FormData();form.append(key,val);return form},dateValue=(timestamp,hour)=>{var date=new Date(timestamp),zeros=num=>num<10?'0'+num:''+num,dateStamp=[date.getFullYear(),zeros(date.getMonth()+1),zeros(date.getDate())].join('-'),hourStamp=['T',zeros(date.getHours()),':',zeros(date.getMinutes())].join('');return!hour?dateStamp:dateStamp+hourStamp},linearize=obj=>{var recurse=doc=>withAs(doc[_.keys(doc)[0]],value=>typeof(value)==='object'?_.map(value,(val,key)=>recurse({[_.keys(doc)[0]+'.'+key]:val})):doc);return _.fromPairs(_.flattenDeep(recurse({doc:obj})).map(i=>[_.keys(i)[0].substr(4),_.values(i)[0]]))}afState.form[opts.id]=opts.doc?_.assign(afState.form[opts.id],linearize(opts.doc)):afState.form[opts.id];var attr={form:
@rikyperdana
rikyperdana / mitGen.js
Created May 14, 2024 01:14
Minified Mithril App Generator CDN
var m,_,mgState={},comps={},state={},withAs=(opts,cb)=>cb(opts),ifit=(opts,cb)=>Boolean(opts)&&cb(opts),ands=array=>array.reduce((a,b)=>a&&b,true),makeArray=n=>[...Array(n).keys()],makeIconLabel=(icon,label)=>[icon&&m('span.icon',m('i.fas.fa-'+icon)),m('span',label)],poster=(url,body,cb)=>fetch(url,{headers:{'Content-Type':'application/json'},method:'post',body:JSON.stringify(body)}).then(res=>res.json()).then(cb),mitGen=opts=>({view:()=>m('div',{class:'has-background-light'},opts.theme&&m('link',{rel:'stylesheet',href:`https://unpkg.com/bulmaswatch/${opts.theme }/bulmaswatch.min.css`}),m('nav.navbar.is-primary.is-fixed-top',m('.navbar-brand',m('a.navbar-item',{onclick:()=>[_.assign(mgState,{comp:undefined}),m.redraw()]},opts.brand.full||opts.brand.name),m('.navbar-burger',{role:'button',class:mgState.burgerMenu&&'is-active',onclick:()=>mgState.burgerMenu=!mgState.burgerMenu},_.range(3).map(i=>m('span',{'aria-hidden':true})))),m('.navbar-menu',{class:mgState.burgerMenu&&'is-active'},m('.navbar-start',_.map(op
var atState={},ors=array=>array.find(Boolean),ands=array=>array.reduce((a,b)=>a&&b,true),withAs=(obj,cb)=>cb(obj),ifit=(obj,cb)=>Boolean(obj)&&cb(obj),timestamp=str=> +(new Date(str)),atModify=(rows,opts)=>rows .filter(i=>withAs({start:_.get(atState,[opts.id,'start_range']),end:_.get(atState,[opts.id,'end_range']),func:eval(_.get(atState,[opts.id,'rangeFunc']))},({start,end,func})=>ands([start,end,timestamp(start)<timestamp(end)])?func(i,timestamp(start),timestamp(end)):i)).filter(i=>ands(_.map(_.get(atState,[opts.id,'filters']),(val,key)=>opts.filters[key].find(j=>j.label===val)).map(j=>j.func(i.data)))).filter(i=>_.values(i.row).map(_.lowerCase).join('').includes(_.get(atState,[opts.id,'search'])||'')).sort((a,b)=>_.get(atState,[opts.id,'sortBy'])&&_[_.get(atState,[opts.id,'sortWay'])?'gt':'lt'](a.row[_.get(atState,[opts.id,'sortBy'])],b.row[_.get(atState,[opts.id,'sortBy'])])?-1:1).slice((_.get(atState,[opts.id,'activeStep'])||0)*(_.get(atState,[opts.id,'pagination'])||0),((_.get(atState,[opts.id,'activeSt
@rikyperdana
rikyperdana / autoForm.js
Created May 14, 2024 01:09
Minified Mithril AutoForm CDN
var m,_,afState={arrLen:{},form:{}},{stringify,parse}=JSON,autoForm=opts=>({view:()=>{var withAs=(obj,cb)=>cb(obj),ifit=(obj,cb)=>Boolean(obj)&&cb(obj),ors=array=>array.find(Boolean),ands=array=>array.reduce((a,b)=>a&&b,true),normal=name=>name.replace(/\d/g,'$'),fileData=(key,val)=>{var form=new FormData();form.append(key,val);return form},dateValue=(timestamp,hour)=>{var date=new Date(timestamp),zeros=num=>num<10?'0'+num:''+num,dateStamp=[date.getFullYear(),zeros(date.getMonth()+1),zeros(date.getDate())].join('-'),hourStamp=['T',zeros(date.getHours()),':',zeros(date.getMinutes())].join('');return!hour?dateStamp:dateStamp+hourStamp},linearize=obj=>{var recurse=doc=>withAs(doc[_.keys(doc)[0]],value=>typeof(value)==='object'?_.map(value,(val,key)=>recurse({[_.keys(doc)[0]+'.'+key]:val})):doc);return _.fromPairs(_.flattenDeep(recurse({doc:obj})).map(i=>[_.keys(i)[0].substr(4),_.values(i)[0]]))}afState.form[opts.id]=opts.doc?_.assign(afState.form[opts.id],linearize(opts.doc)):afState.form[opts.id];var attr={form:
@rikyperdana
rikyperdana / pathFinder.js
Created April 28, 2024 09:44
Pathfinder Algorithm and Vehicle Routing Problem in Functional Javascript
cityMap = {
a: {b: 20, d: 80, g: 90},
b: {f: 10},
c: {f: 50, h: 20, d: 10},
d: {g: 20, c: 10},
e: {b: 50, g: 30},
f: {c: 10, d: 40},
g: {a: 20},
h: {h: 0}
}
@rikyperdana
rikyperdana / matrix.js
Last active April 19, 2024 02:36
Matrix Operations in JS
withAs = (obj, cb) => cb(obj)
sum = arr => arr.reduce((a, b) => a + b)
mul = arr => arr.reduce((a, b) => a * b)
sub = arr => arr.splice(1).reduce((a, b) => a - b, arr[0])
deepClone = obj => JSON.parse(JSON.stringify(obj))
shifter = (arr, step) => [
...arr.splice(step),
...arr.splice(arr.length - step)
]
@rikyperdana
rikyperdana / functhon.py
Last active June 23, 2023 16:16
Functional Python
def reduce(list, init, func):
for i in list: init = func(init, i)
return init
filter = lambda list, func: [i for i in list if func(i)]
find = lambda list, func: filter(list, func)[0]
map = lambda list, func: [func(i) for i in list]
sum = lambda list: reduce(list, 0, lambda a, b: a + b)
mul = lambda list: reduce(list, 1, lambda a, b: a * b)
ors = lambda list: find(list, bool)
ands = lambda list: all(list) and list[-1]
@rikyperdana
rikyperdana / statistics.js
Last active September 25, 2021 03:46
Statistics in JS with Functional Paradigm
var
withThis = (obj, cb) => cb(obj),
get = prop => obj => obj[prop],
add = array => array.reduce((acc, inc) => acc + inc),
sub = array => array.reduce((acc, inc) => acc - inc),
mul = array => array.reduce((acc, inc) => acc * inc),
pow = asc => num => Math.pow(num, asc),
range = array => Math.max(...array) - Math.min(...array),
between = (low, middle, high) =>
(low <= middle) && (middle <= high),
@rikyperdana
rikyperdana / autoform-introduction.md
Created June 27, 2020 00:11
How I built Automatic Form Generator based on Mithril

How I built Automatic Form Generator based on Mithril

I still remember the days when I consistently glorify Meteor JS for all of my projects and event wrote a dedicated medium post titled 'Why I chose Meteor JS'. There was never a day since then I haven't thanked MeteorJS for all goodness it brought that delivers me to become a bit matured js developer. It lifted all the burden of steep learning curves of other frameworks and kept me away from the so called Javascript Fatigueness all around. And one of the biggest credit of my achievements has to go to aldeed:autoform that allows me and other MeteorJS developer to easily build forms in the simplest manner of writing a schema. I wouldn't dare to imagine how troublesome and terrible the tasks would be without it as my projects are mostly consists of deeply nested forms for database management and hospital information.

m.render(document.body, m('table', m('thead', m('tr', m('th', 'Kolom1'))), m('tbody', m('tr', m('td', 'baris1')))));