Skip to content

Instantly share code, notes, and snippets.

@umayr
umayr / inject-script.js
Created Apr 15, 2021
How to inject the script in the body of the document and wait till it has been loaded completely
View inject-script.js
// 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 Nov 4, 2019
Quick Comparison between an Inline Styling and Styled Components
View Benchmarks.stories.jsx
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;
View gist:781ccbaa3fad90908e25de5b9176c510
'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 Jul 9, 2019
Ignore a directory and a file in Find command
View README.md

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 Jan 24, 2021
Dracula color scheme for FZF
View README.md

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'],
View foo.go
package Foo
import "fmt"
func Fn() {
fmt.Printf("foo")
}
@umayr
umayr / sqrt.go
Last active Jan 2, 2017 — forked from abesto/gist:3476594
Go: Newton's method for square root
View sqrt.go
/*
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 Dec 1, 2016
Multiple API calls with Redux Thunks.
View multiple-api-calls-redux-thunk.js
function doSomething() {
return dispatch =>
fetch(
'/api/something'
).then(
response => response.json()
).then(
json => dispatch({ type: DO_SOMETHING, json }),
err => dispatch({ type: SOMETHING_FAILED, err })
);
View terminator.ts
'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}`);
View decorators-example.ts
'use strict';
function classDecorator(target: any) {
console.log('class decorator');
}
function propertyDecorator(target: any, key: string | symbol) {
console.log('property decorator');
}