Skip to content

Instantly share code, notes, and snippets.

View basith374's full-sized avatar

Basith Kunimal basith374

View GitHub Profile
@basith374
basith374 / fetch.js
Created August 11, 2023 15:05
simple fetch
fetch(url).then(rsp ⇒ rsp.json())
@basith374
basith374 / split.js
Created July 16, 2021 11:02
Split CSV row using javascript
function splitRow(row) {
const cols = [];
while (row.length) {
let commaIdx = row.indexOf(",");
const quoteIdx = row.indexOf("\"");
if(quoteIdx > -1 && commaIdx > quoteIdx) {
commaIdx = row.slice(1).indexOf("\"") + 2;
}
const stripQuote = (str) => {
return str[0] === "\"" && str[str.length - 1] === "\"" ? str.slice(1, str.length - 1) : str
import React, { useEffect, useRef } from 'react'
import * as PIXI from 'pixi.js'
import texture from 'cloud.jpg'
export default function RippleImage({ src, style }) {
const ref = useRef()
useEffect(() => {
const app = new PIXI.Application({
width: window.innerWidth,
height: window.innerHeight
import React, { useEffect, useRef } from 'react'
import iro from '@jaames/iro'
function ColorPicker({ setColor, color }) {
const ref = useRef()
const colorPicker = useRef()
useEffect(() => {
const cp = (colorPicker.current = new iro.ColorPicker(ref.current, {
color
}))
import Parallax from './parallax'
import bg1 from './assets/bg1.png'
import bg2 from './assets/bg2.png'
import bg3 from './assets/bg3.png'
function App() {
return <Parallax images={[bg1, bg2, bg3]} />
}
@basith374
basith374 / parallax.js
Last active May 6, 2021 04:26
parallax
import React, { useRef, useEffect } from 'react'
const MARGIN = 100
const STEP = 0.2
export default function Parallax({ images }) {
const refs = useRef({})
const parent = useRef()
useEffect(() => {
for (const i in refs.current) {
@basith374
basith374 / index.html
Created February 9, 2021 08:00
pubsub example
<doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<style>
body {
margin: none;
}
.panel {
border: 1px solid #ccc;
@basith374
basith374 / site
Created August 21, 2020 14:48
nginx conf
server {
listen 80;
listen [::]:80;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name example.com;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
@basith374
basith374 / index.js
Created July 18, 2020 11:34
d3 v4 line chart
import { scaleLinear, scaleLog, axisLeft, axisBottom, select, line, format } from 'd3';
const yScale = scaleLog().domain([0, 100]).range([300, 0])
const xScale = scaleLinear().domain([1, 100]).range([0, 500]);
const pathline = line().x(d => xScale(d.x)).y(d => yScale(d.y));
axisLeft(yScale).tickValues([maxViews, minViews]).tickFormat(format('.2s'))(select('.leftAxis'));
axisBottom(xScale).tickValues([1, songs.length])(select('.bottomAxis'));
@basith374
basith374 / index.php
Created July 5, 2020 18:00
ebay search
<?php
if(isset($_GET['productid'])) {
$ch = curl_init('http://ebay-api.thedcevents.com/api/findproduct/' . $_GET['productid']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
// $result = '{"title":"foo","url":"bar","img":"baz","thumbnails":["asd","qwe"]}';
$result = json_decode($output);
if($result->status == 'SUCCESS') {
$item = $result->data;