Skip to content

Instantly share code, notes, and snippets.

View tarex's full-sized avatar
🎯
Focusing

Tareq Jobayere tarex

🎯
Focusing
View GitHub Profile
@tarex
tarex / useSpeechToText.ts
Created February 6, 2024 16:20 — forked from KristofferEriksson/useSpeechToText.ts
An experimental React hook for real-time speech-to-text using the Web Speech API
import { useCallback, useEffect, useState } from "react";
// Define custom types for SpeechRecognition and SpeechRecognitionEvent
interface ISpeechRecognitionEvent extends Event {
results: SpeechRecognitionResultList;
resultIndex: number;
}
interface ISpeechRecognition extends EventTarget {
lang: string;
@tarex
tarex / useCookie.ts
Created January 29, 2024 11:33 — forked from KristofferEriksson/useCookie.ts
A hook to easily read and update browser cookies. Plus, it auto-updates your component when cookie values change
import { useEffect, useState } from "react";
type UseCookieReturnType = {
cookie: string | undefined;
setCookie: (value: string, days?: number) => void;
};
const useCookie = (cookieName: string): UseCookieReturnType => {
const getCookie = (name: string): string | undefined => {
const value = `; ${document.cookie}`;
<?php
namespace App\Libraries\Queue;
use Illuminate\Events\Dispatcher;
use Illuminate\Queue\DatabaseQueue;
use Illuminate\Support\Str;
use Laravel\Horizon\Events\JobDeleted;
use Laravel\Horizon\Events\JobPushed;
use Laravel\Horizon\Events\JobReleased;
@tarex
tarex / list.md
Created October 8, 2021 20:37 — forked from ih2502mk/list.md
Quantopian Lectures Saved
@tarex
tarex / smtp-gmail-send.go
Created December 25, 2020 22:36 — forked from jpillora/smtp-gmail-send.go
Send email using Go (Golang) via GMail with net/smtp
package main
import (
"log"
"net/smtp"
)
func main() {
send("hello there")
}
@tarex
tarex / Dockerfile
Created December 16, 2020 09:37 — forked from kandros/.dockerignore
Dockerfile for next.js projects
FROM node:15.3.0-alpine3.10 as deps
WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn --production --silent
RUN cp -R node_modules prod_node_modules
RUN yarn --frozen-lockfile --silent
FROM deps as builder
WORKDIR /app
COPY . .
@tarex
tarex / hooks.js
Created May 23, 2020 11:40 — forked from fnky/hooks.js
React Hooks: useReducer with actions and selectors (Redux-like)
function useSelectors(reducer, mapStateToSelectors) {
const [state] = reducer;
const selectors = useMemo(() => mapStateToSelectors(state), [state]);
return selectors;
}
function useActions(reducer, mapDispatchToActions) {
const [, dispatch] = reducer;
const actions = useMemo(() => mapDispatchToActions(dispatch), [dispatch]);
return actions;

Run each of the following lines, replacing yourdomain.com and codehere with your details:

now dns add yourdomain.com @ TXT google-site-verification=codehere
now dns add yourdomain.com @ MX ASPMX.L.GOOGLE.COM 1
now dns add yourdomain.com @ MX ALT1.ASPMX.L.GOOGLE.COM 5
now dns add yourdomain.com @ MX ALT2.ASPMX.L.GOOGLE.COM 5
now dns add yourdomain.com @ MX ALT3.ASPMX.L.GOOGLE.COM 10
now dns add yourdomain.com @ MX ALT4.ASPMX.L.GOOGLE.COM 10
@tarex
tarex / function.php
Created April 4, 2020 15:19
WP Rest API Cors
function add_custom_headers() {
add_filter( 'rest_pre_serve_request', function( $value ) {
header( 'Access-Control-Allow-Headers: Authorization, X-WP-Nonce,Content-Type, X-Requested-With');
header( 'Access-Control-Allow-Origin: *' );
header( 'Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE' );
header( 'Access-Control-Allow-Credentials: true' );
return $value;
} );

Server side printing with Google Cloud Print API from a PHP application

It took me quite some time to figure out how to print properly from a web application. I will explain here how I did it, so you don't have to spend the same time.

Authorization

Google Cloud Print API uses OAuth 2.0 for authorization.

As explained [here][1] on the Google Developer page, the best way to use OAuth with the Google API is with a Google service account. Create a service account as explained on the Google Developer page.

To use OAuth a library is required. Google has published the [Google API PHP client library][2]. If you want to use the examples from the Developer pages, you need to use version 1 of the library. In this article I use version 2 of the library.