Skip to content

Instantly share code, notes, and snippets.

View AhmetEnesKCC's full-sized avatar
🖥️
Coding...

Ahmet Enes KCC AhmetEnesKCC

🖥️
Coding...
View GitHub Profile
@AhmetEnesKCC
AhmetEnesKCC / cashier.go
Created August 28, 2023 13:15
cashier app
package main
import (
"fmt"
)
type Item struct {
Name string
Price float64
discount float64
```go
package main
import (
"fmt"
)
type Item struct {
Name string
Price float64
#include <iostream>
using namespace std;
void swap(int * array, int index1, int index2) {
int temp = array[index1];
array[index1] = array[index2];
array[index2] = temp;
}
bool willMoveNext(int number, int nextNumber) {
{
"extends": [
"next",
"eslint:recommended",
"next/core-web-vitals",
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended"
],
"parser": "@typescript-eslint/parser",
@AhmetEnesKCC
AhmetEnesKCC / index.jsx
Created March 19, 2022 13:45
website theme related to system - custom hook using
import React from "react";
import {useSetThemeRelatedToSystem }
export default App = () => {
const {theme} = useSetThemeRelatedToSystem();
return <div> {theme ? theme : "getting system theme" } </div>
}
@AhmetEnesKCC
AhmetEnesKCC / useSetThemeRelatedToSystem.js
Created March 19, 2022 13:42
set sytem theme related to system custom-hook
import {useState, useEffect} from "react";
import {getSystemTheme, watchSytemTheme, setTheme as setWebsiteTheme } from "functions-path" // you need export them separately. I changed name for prevent name collision with local state below.
// Creating custom hook - must be 'use' at the starting of function name
const useSetThemeRelatedToSystem = () => {
// create theme state
const setThemeRelatedToSystem = () => {
// ... rest of the function's code
}
// Plain JS
document.addEventListener("DOMContentLoad", () => {
setThemeRelatedToSystem();
})
@AhmetEnesKCC
AhmetEnesKCC / setThemeRelatedToSystem.js
Last active March 19, 2022 13:29
Set Theme Related To System
const setThemeRelatedToSystem = () => {
const getSystemtheme = () => {
// ... rest of the function code
}
const setTheme = (theme) => {
// ... rest of the funciton code
}
@AhmetEnesKCC
AhmetEnesKCC / watchSystemTheme.js
Created March 19, 2022 13:05
watch system theme
const watchSystemTheme = (cb) => { // I will use callback for that
// Addlistener to matchmedia for light and dark mode
window.matchMedia("(prefers-color-scheme: dark)").addListener(e => {
e.matches && cb("dark"); // If it is dark we called the defined callback with dark argument
})
window.matchMedia("(prefers-color-scheme: light)").addListener(e => {
e.matches && cb("light"); // Else If it is dark we called the defined callback with light argument
})
}
const setTheme = (theme) => {
const rootElement = document.querySelector("html");
// Set <html daa-theme="theme"> to change children styles
rootElement.setQuery("data-theme", theme);
}