Skip to content

Instantly share code, notes, and snippets.

View salmanx's full-sized avatar

Salman Mahmud salmanx

  • Dhaka, Bangladesh
View GitHub Profile
@salmanx
salmanx / calender_overlapp.rb
Last active June 3, 2024 09:47
Ruby program to check overlapping calendar
class Calender
attr_accessor :start_time, :end_time
def initialize(start_time:, end_time:)
@start_time = start_time
@end_time = end_time
end
end
def is_overlapping?(c1, c2)
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Http;
class MainContoller extends Controller
{
public function login(Request $request)
const str = "cats AND*Dogs-are Awesome";
// const str = 'a b c d-e-f%g'
const splitted_word = str.split(/\W+/);
const result =
splitted_word[0].toLocaleLowerCase() +
splitted_word
.slice(1)
.slice(-splitted_word.length)
.map((s) => s.charAt(0).toUpperCase() + s.slice(1).toLocaleLowerCase())
.join("");
@salmanx
salmanx / clean_hash.rb
Created March 25, 2023 17:27
Remove invalued values from hash and nested values from hash
def clean_json(hash)
invalid_values = ["N/A", "-", ""]
hash.each do |key, value|
if value.is_a?(Hash)
clean_json(value)
if value.values.any? { |v| invalid_values.include?(v) }
hash.delete(key)
end
elsif value.is_a?(Array)
value.each do |v|
@salmanx
salmanx / media.scss
Created November 22, 2022 16:09
css custom media mixin
$mobileMin: 0px;
$mobileMax: 425px;
$tabletMin: 426px;
$tabletMax: 700px;
$laptopMin: 941px;
$laptopMax: 1440px;
$desktopMin: 1441px;
$desktopMax: 1920px;
$largeDisplayMin: 1921px;
@salmanx
salmanx / useRef.jsx
Created January 11, 2022 18:24
Persist previous state value after re render uing react useRef() hooks
export default function UseRef() {
const [name, setName] = useState('');
const renderCount = useRef(1);
const prevName = useRef('');
useEffect(() => {
renderCount.current = renderCount.current + 1
prevName.current = name;
})
import React, { useEffect, useState } from "react";
export default function WindowResize() {
const [windowWidth, setWindowWidth] = useState(window.innerWidth);
const handleWindowResize = () => setWindowWidth(window.innerWidth)
useEffect(() => {
window.addEventListener('resize', handleWindowResize);
@salmanx
salmanx / readme.md
Created August 1, 2021 14:21 — forked from maxivak/readme.md
Integrating Gem/Engine and Main Rails App
// basic uses
// user component using useState
const User = () => {
const [userDetails, setUserdetails] = useState();
const [loading, setLoading] = useState(false);
const [error, setError] = useState();
useEffect(() => {
setLoading(true);
@salmanx
salmanx / map_array_from.js
Created April 10, 2021 14:33
.map() also has a substitute that we can use which is .from()
let cars = [
{
"color": "purple",
"type": "minivan",
"registration": new Date('2017-01-03'),
"capacity": 7
},
{
"color": "red",
"type": "station wagon",