Skip to content

Instantly share code, notes, and snippets.

@sabha
sabha / counter.elm
Last active March 16, 2017 17:17
Elm Multiple Counter sample using List Type & Array
-- Try the sample using this URL
-- http://elm-lang.org/try
import Html exposing (beginnerProgram, div, button, text, p, Html, span)
import Html.Events exposing (onClick)
import Array
main =
beginnerProgram { model = [0,7], view = view, update = update }
@sabha
sabha / index.js
Last active August 14, 2017 22:39
Node http File system and JSON exp
const http = require('http')
const url = require("url");
const fs = require('fs');
const port = 3000
const requestHandler = (request, response) => {
var pathname = url.parse(request.url).pathname;
console.log("Request for " + pathname + " received. "+(pathname === '/persons'));
var json = JSON.parse(fs.readFileSync('./persons.json', 'utf8'));
@sabha
sabha / circle.html
Created September 22, 2017 20:40
Circle - Velocity - Acceleration
<!DOCTYPE html>
<html>
<body>
<canvas id="canvas" width="400" height="600">
Your browser does not support the HTML5 canvas tag.</canvas>
<script>
function Vector(x,y) {
this.x = x;
@sabha
sabha / index.html
Created September 21, 2017 22:23
Fractal Tree
<!DOCTYPE html>
<html>
<body>
<canvas id="canvas" width="900" height="300" style="border:1px solid #000000; background: #F4F6F6">
Your browser does not support the HTML5 canvas tag.</canvas>
<script>
function Vector(x,y) {
this.x = x;
@sabha
sabha / reactChild.js
Created November 10, 2017 22:48
Recursion React Children
var childrens = [{name: 'ql-0', childrens : [ { name: 'ql-0-0' }] },{name: 'ql-1'}, {name: 'ql-2', childrens : [ { name: 'ql-2-0' }, { name: 'ql-2-1' }] }]
function recursive(children, i){
return children.map((child, index) => {
if(child.childrens) return Object.assign({},child,{index: `${i}-${index}`, childrens: recursive(child.childrens, `${i}-${index}`)});
else return Object.assign({},child,{index: `${i}-${index}`});
})
}
var a = recursive(childrens,'ql');
@sabha
sabha / Jitter.html
Created February 11, 2018 17:33
Jitter
<!DOCTYPE html>
<html>
<body>
<canvas id="myCanvas" width="200" height="100" style="border:1px solid #d3d3d3;">
Your browser does not support the HTML5 canvas tag.</canvas>
<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
@sabha
sabha / vector.html
Last active February 18, 2018 04:31
Vector
<!DOCTYPE html>
<html>
<body>
<canvas id="myCanvas" width="300" height="150" style="border:1px solid #d3d3d3;">
Your browser does not support the HTML5 canvas tag.</canvas>
<script>
var mouseX = 0;
var mouseY = 0;
@sabha
sabha / circlePattern.html
Last active March 22, 2018 15:09
Circle Pattern
<!DOCTYPE html>
<html>
<body>
<script>
function getRandomColor() {
var letters = '0123456789ABCDEF';
var color = '#';
for (var i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
@sabha
sabha / mandala.html
Created March 23, 2018 17:27
Mandala
<!DOCTYPE html>
<html>
<body>
<script>
function bootStrapMandala(){
var name = "canvas"+Math.floor(Math.random() * 1000);
var canv = document.createElement('canvas');
@sabha
sabha / index.html
Last active March 25, 2018 07:10
Sin Cos Wave
<!DOCTYPE html>
<html>
<body>
<canvas id="myCanvas" width="600" height="600" style="border:1px solid #d3d3d3;">
Your browser does not support the HTML5 canvas tag.</canvas>
<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");