Skip to content

Instantly share code, notes, and snippets.

@umayr
umayr / inject-script.js
Created April 15, 2021 17:44
How to inject the script in the body of the document and wait till it has been loaded completely
// injects the script in the body of the document.
// returns a promise that gets resolves once the script has been loaded in the document
export const injectScript = (url, document = window.document) => {
const script = document.createElement('script');
script.src = url;
script.type = 'text/javascript';
script.async = true;
const body = document.getElementsByTagName('body')?.[0] ?? null;
if (body === null) {
@umayr
umayr / Benchmarks.stories.jsx
Last active November 4, 2019 21:23
Quick Comparison between an Inline Styling and Styled Components
import React from 'react';
import { Button } from 'antd';
import styled from 'styled-components';
import { storiesOf } from '@storybook/react';
const stories = storiesOf('Benchmarks', module);
const StyledButton = styled(Button)`
&& {
display: block;
'use strict';
import React, { PureComponent, useState, useEffect } from 'react';
import { AppRegistry, StyleSheet, Text, TouchableOpacity, View } from 'react-native';
import { RNCamera } from 'react-native-camera';
import Permissions from 'react-native-permissions';
const CameraApp = () => {
let [flash, setFlash] = useState('off')
let [zoom, setZoom] = useState(0)
let [autoFocus, setAutoFocus] = useState('on')
@umayr
umayr / README.md
Created July 9, 2019 14:38
Ignore a directory and a file in Find command

Consider the following scenario:

λ tree .                                                                                                                                                         (folder) 10:34:52
.
├── delete-file1
├── delete-file2
├── delete-file3
├── keep-file1
└── keep-folder
@umayr
umayr / README.md
Last active September 29, 2023 16:40
Dracula color scheme for FZF

Dracula Color Scheme for FZF

Preview

if you're using fish shell, you can add this in your fish config:

let g:fzf_colors = {
\ 'fg': ['fg', 'Normal'],
\ 'bg': ['bg', 'Normal'],
package Foo
import "fmt"
func Fn() {
fmt.Printf("foo")
}
@umayr
umayr / sqrt.go
Last active January 2, 2017 15:58 — forked from abesto/gist:3476594
Go: Newton's method for square root
/*
A Tour of Go: page 44
http://tour.golang.org/#44
Exercise: Loops and Functions
As a simple way to play with functions and loops, implement the square root function using Newton's method.
In this case, Newton's method is to approximate Sqrt(x) by picking a starting point z and then repeating: z - (z*z - x) / (2 * z)
@umayr
umayr / multiple-api-calls-redux-thunk.js
Created December 1, 2016 21:43
Multiple API calls with Redux Thunks.
function doSomething() {
return dispatch =>
fetch(
'/api/something'
).then(
response => response.json()
).then(
json => dispatch({ type: DO_SOMETHING, json }),
err => dispatch({ type: SOMETHING_FAILED, err })
);
'use strict';
function log(type:string) {
return function(target: any, key: string, descriptor: PropertyDescriptor) {
let fn = descriptor.value;
descriptor.value = function(...args:any[]) {
console.log(`[${type.toLocaleUpperCase()}]: Invoking method - ${key}`);
let result = fn.apply(this, args);
console.log(`[${type.toLocaleUpperCase()}]: Completed method - ${key}`);
'use strict';
function classDecorator(target: any) {
console.log('class decorator');
}
function propertyDecorator(target: any, key: string | symbol) {
console.log('property decorator');
}