Skip to content

Instantly share code, notes, and snippets.

@umayr
umayr / recover-deleted-branch.sh
Created April 1, 2016 11:41
How to recover a deleted branch
## Pre-requisite: You have to know your last commit message from your deleted branch.
git reflog
# Search for message in the list
# a901eda HEAD@{18}: commit: <last commit message>
# Now you have two options, either checkout revision or HEAD
git checkout a901eda
# Or
git checkout HEAD@{18}
@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 / 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'],
@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 })
);
@umayr
umayr / interface-example.ts
Created August 29, 2016 19:49
An Interface example for TypeScript
interface IFunc {
(n: number[]): number;
}
interface IOperations {
add: IFunc;
sub: IFunc;
mul: IFunc;
div: IFunc;
}
@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 / promise.js
Last active July 10, 2017 06:29
Promise API example in native javascript
function getGithubUserInfo(username) {
return new Promise(function (resolve, reject) {
// Do the usual XHR stuff
var url = "https://api.github.com/users/" + username;
var req = new XMLHttpRequest();
req.open('GET', url);
req.onload = function () {
package Foo
import "fmt"
func Fn() {
fmt.Printf("foo")
}