Skip to content

Instantly share code, notes, and snippets.

View Alimjanov-Ibragim's full-sized avatar
🎯
Focusing

Ibragim Alimjanov-Ibragim

🎯
Focusing
View GitHub Profile
@felipeskroski-zz
felipeskroski-zz / degToCard.js
Last active February 24, 2022 20:27
Javascript function to convert wind direction in degrees to cardinal.
var degToCard = function(deg){
if (deg>11.25 && deg<=33.75){
return "NNE";
}else if (deg>33.75 && deg<=56.25){
return "ENE";
}else if (deg>56.25 && deg<=78.75){
return "E";
}else if (deg>78.75 && deg<=101.25){
return "ESE";
}else if (deg>101.25 && deg<=123.75){
@gaearon
gaearon / prepack-gentle-intro-1.md
Last active May 3, 2024 12:56
A Gentle Introduction to Prepack, Part 1

Note:

When this guide is more complete, the plan is to move it into Prepack documentation.
For now I put it out as a gist to gather initial feedback.

A Gentle Introduction to Prepack (Part 1)

If you're building JavaScript apps, you might already be familiar with some tools that compile JavaScript code to equivalent JavaScript code:

  • Babel lets you use newer JavaScript language features, and outputs equivalent code that targets older JavaScript engines.
@gaearon
gaearon / modern_js.md
Last active April 18, 2024 15:01
Modern JavaScript in React Documentation

If you haven’t worked with JavaScript in the last few years, these three points should give you enough knowledge to feel comfortable reading the React documentation:

  • We define variables with let and const statements. For the purposes of the React documentation, you can consider them equivalent to var.
  • We use the class keyword to define JavaScript classes. There are two things worth remembering about them. Firstly, unlike with objects, you don't need to put commas between class method definitions. Secondly, unlike many other languages with classes, in JavaScript the value of this in a method [depends on how it is called](https://developer.mozilla.org/en-US/docs/Web/Jav
@gaearon
gaearon / like_button.js
Last active November 19, 2020 06:02
JSX version of LikeButton
'use strict';
class LikeButton extends React.Component {
constructor(props) {
super(props);
this.state = { liked: false };
}
render() {
if (this.state.liked) {
@gaearon
gaearon / uselayouteffect-ssr.md
Last active May 2, 2024 13:42
useLayoutEffect and server rendering

If you use server rendering, keep in mind that neither useLayoutEffect nor useEffect can run until the JavaScript is downloaded.

You might see a warning if you try to useLayoutEffect on the server. Here's two common ways to fix it.

Option 1: Convert to useEffect

If this effect isn't important for first render (i.e. if the UI still looks valid before it runs), then useEffect instead.

function MyComponent() {
@yunusga
yunusga / .htaccess
Last active June 15, 2023 09:46
RewriteRule для WordPress директории uploads. На случай если нет возможности держать файлы загрузок на своем сервере при тестировании.
# за редирект отвечает
# RewriteRule ^wp-content/uploads/(.*)$ https://<production site>/wp-content/uploads/$1 [R=302,NC,L]
# должна быть сразу после RewriteEngine On
# <wp test directory> необходим если сайт лежит в директории основного домена, например site.com/dev
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^wp-content/uploads/(.*)$ https://<production site>/wp-content/uploads/$1 [R=302,NC,L]
# RewriteRule ^wp-content\/uploads\/(?!(2022\/08)\/)(.*)$ https://divina-bellezza.ru/wp-content/uploads/$2 [R=302,NC,L]
RewriteBase /<wp test directory>/
RewriteRule ^index\.php$ - [L]
@rickyhaswifi
rickyhaswifi / netlify.toml
Last active August 10, 2023 00:48
React Router Netlify - Fix for not found page
#https://stackoverflow.com/questions/58065603/netlify-renders-404-on-page-refresh-using-react-and-react-router
[[redirects]]
from = "/*"
to = "/index.html"
status = 200
/**
* @param {string} path
* @returns {Boolean}
*/
export function isExternal(path) {
return /^(https?:|mailto:|tel:)/.test(path)
}
/**
* @param {string} str
@KamaMakh
KamaMakh / axiosTemp.js
Last active December 10, 2020 11:18
axios template
let axios = require("axios")
let axiosInstance = axios.create({
httpsAgent: new https.Agent({
rejectUnauthorized: false
}),
transformRequest: [(data, headers) => {
headers["Accept-Language"] = "en";
if (/* token */) {
@KamaMakh
KamaMakh / base64Methods.js
Created December 10, 2020 10:35
Methods for base64
{
toBase64: file => new Promise((resolve, reject) => {
if (file) {
const reader = new FileReader()
reader.readAsDataURL(file.raw)
reader.onload = () => resolve(reader.result)
reader.onerror = error => reject(error)
} else {
reject()
}