Skip to content

Instantly share code, notes, and snippets.

@saitergun
saitergun / bridgecode.php
Created August 29, 2022 19:45 — forked from abraham/bridgecode.php
Example code for getting an OAuth 1.0a access_token from Twitter @anywhere users.
<?php
// Download TwitterOAuth from http://github.com/abraham/twitteroauth.
require_once('twitteroauth/twitteroauth.php');
// Get consumer keys from http://dev.twitter.com/apps.
$consumer_key = '';
$consumer_secret = '';
$oauth_bridge_code = '';
@saitergun
saitergun / asyncForEach.ts
Last active June 24, 2024 09:35
async for each
async function asyncForEach<T>(
array: Array<T>,
callbackfn: {
(value: T, index: number, array: T[]): Promise<void> | void;
}
) {
for (let index = 0; index < array.length; index++) {
await callbackfn(array[index], index, array);
}
}
@saitergun
saitergun / README.md
Created May 5, 2023 18:32
add seperator to macos dock

Regular spacer script:

defaults write com.apple.dock persistent-apps -array-add '{"tile-type"="spacer-tile";}'; killall Dock

Small spacer script:

defaults write com.apple.dock persistent-apps -array-add '{"tile-type"="small-spacer-tile";}'; killall Dock
@saitergun
saitergun / createSessionsGroups.ts
Created June 5, 2023 09:49
create session times with between two shift times
import moment from 'moment'
function createSessionsGroups(duration: number, shiftStart: moment.Moment, shiftEnd: moment.Moment, initialSessions: Array<string> = []): Array<string> {
const sessions: Array<string> = [...initialSessions]
const sessionStart = moment().hour(shiftStart.hour()).minute(shiftStart.minute())
const sessionEnd = sessionStart.clone().add(duration, 'minute')
sessions.push(sessionStart.format('HH:mm'))
const availableTimeZones = [
'Etc/GMT+12',
'Etc/GMT+11',
'Pacific/Honolulu',
'America/Anchorage',
'America/Santa_Isabel',
'America/Los_Angeles',
'America/Phoenix',
'America/Chihuahua',
'America/Denver',
@saitergun
saitergun / NProgressProvider.tsx
Created July 30, 2023 18:42
NProgress provider component for Next.js app routing
'use client'
import { usePathname } from 'next/navigation'
import { useEffect, useRef } from 'react'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
type Props = {
children: React.ReactNode
@saitergun
saitergun / Echart.tsx
Created February 8, 2024 09:57 — forked from suhaotian/Echart.tsx
echarts with typescript
import React, { useState, useRef, useEffect, useMemo, useLayoutEffect, useImperativeHandle, forwardRef, Ref } from 'react'
import echarts, { ECOption } from './echarts-ref';
export type EchartProp = {
option: ECOption,
style?: {
width: string,
height: string
}
className?: string
import { useEffect } from 'react'
import { useRouter } from 'next/navigation'
import { NavigateOptions } from 'next/dist/shared/lib/app-router-context.shared-runtime'
export default function usePageLeavingConfirm(showConfirm: boolean) {
const router = useRouter()
const handleAnchorClick = (e: MouseEvent) => {
if (e.button !== 0) return // only handle left-clicks
const targetUrl = (e.currentTarget as HTMLAnchorElement).href