Skip to content

Instantly share code, notes, and snippets.

View nipunadodan's full-sized avatar
💭
I may be slow to respond.

Nipuna Dodantenna nipunadodan

💭
I may be slow to respond.
View GitHub Profile

Code Style Guide for React/Next.js

A comprehensive guide for maintaining consistent code style in our React/Next.js applications.

Core Principles

  • Write functional, pure components
  • Keep components small and focused (50-75 lines maximum)
  • Follow a "return early" coding style
  • Maintain separation of concerns
@nipunadodan
nipunadodan / SkiaChartSample.tsx
Last active May 14, 2024 04:25
SkiaChart: Bug #174
import React, {useRef, useEffect} from 'react';
import {View, Dimensions} from 'react-native';
import * as echarts from 'echarts/core';
import {LineChart} from 'echarts/charts';
import {SVGRenderer, SkiaChart} from '@wuba/react-native-echarts';
import {GridComponent, ToolboxComponent, LegendComponent, TooltipComponent, DataZoomComponent, VisualMapComponent, BrushComponent} from 'echarts/components';
import {LabelLayout} from 'echarts/features';
// import { CanvasRenderer } from 'echarts/renderers';
echarts.use([SVGRenderer, LineChart, ToolboxComponent, TooltipComponent, LegendComponent, LabelLayout, DataZoomComponent, GridComponent, VisualMapComponent, BrushComponent,]);
@nipunadodan
nipunadodan / Helpers.js
Last active March 31, 2022 09:51
React.js developers often face the issue of having to restrict pages depending on the user level. This is one and easier way to deal with it.
/**
* Stored the user in the localStorage for the convenience and the demonstration.
* You can store and retrieve the user from your prefferred data storage option
*/
export function useAuth(props) {
const user = JSON.parse(localStorage.getItem('orange_user'))
if(user)
return props.roles.includes(user.role) || props.minlevel <= user.level
else
@nipunadodan
nipunadodan / traveller-api.php
Last active February 9, 2022 06:22
How to filter posts by a certain post format including "standard" from wp-json api?
<?php
/*
Plugin Name: The Traveller API
Plugin URI: http://nipunadodan.com/wp_plugins
Description: Custom API endpoint additional to the WP_API
Version: 1.0
Author: Nipuna Dodantenna
Author URI: http://nipunadodan.com
License: GPL2
License URI: https://www.gnu.org/licenses/gpl-2.0.html
@nipunadodan
nipunadodan / operafix.sh
Last active November 8, 2021 15:42
Opera browser on Ubuntu has a big issue of not being able to play some video formats due to a licensing issue with ffmpeg. So this is a hack to get it linked with a 3rd party
#!/bin/bash
# Opera browser on Ubuntu has a big issue of not being able to play some video formats due to a licensing issue with ffmpeg.
# So this is a hack to get it linked with a 3rd party
# (installed via snap - the other version didn't work) ffmpeg repository to make the browser play videos again.
# Dependencies: sudo snap install chromium-ffmpeg
biggest=0
for d in /snap/chromium-ffmpeg/current/chromium-ffmpeg-*/ ; do
SUBSTRING=$(echo $d| cut -d'-' -f 4)
SUBSTRING=${SUBSTRING%/}
<?php
/*
* Author: Nipuna Dodantenna
* All rights reserved
* 2016.07.19
* Mod 2019.06.01 - Allowed 12-digit numbers
* Mod 2021.08.09 - More streamlined code base and output as a JSON
*/
header('Content-Type: application/json');
@nipunadodan
nipunadodan / image-upload.html
Last active July 28, 2021 10:52
Relay files received through multipart/form-data using GuzzleHttp
<input name="image-to-upload" type="file" accept="image/*" id="image-to-upload">
@nipunadodan
nipunadodan / sinhala_unicode_converter.html
Last active July 1, 2021 05:52
Sinhala Unicode to Sinhala FM font (ASCII) converter
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Sinhala Unicode Converter</title>
<style>
label{
display: block;
}
textarea{
@nipunadodan
nipunadodan / frameheight.sh
Last active July 13, 2020 02:52
Find where your all HD movies are. Dependencies: ffmpeg
IFS=$'\n'; set -f
BLUE='\033[1;36m'
RED='\033[0;31m'
NC='\033[0m' # No Color
read -p 'Where you want to search (File path): ' FILE_PATH
FILE_PATH=$(eval echo $FILE_PATH)
read -p 'Set the width you want to search (Default HD 1920): ' TEST_HEIGHT
if [ -d "$FILE_PATH" ]; then
for f in $(find "$FILE_PATH" -name '*.mkv' -or -name '*.mp4' -or -name '*.avi'); do
HEIGHT=$(ffprobe -v quiet -select_streams v:0 -show_entries stream=width -of csv=s=x:p=0 $f) #use error instead of quiet if need to print errors