Skip to content

Instantly share code, notes, and snippets.

View adi518's full-sized avatar
🌴
On vacation

Adi adi518

🌴
On vacation
View GitHub Profile
import React from "react";
import { merge, compose } from "lodash/fp";
export const castRouterParams = (keys, caster) => WrappedComponent => ({
match,
...props
}) => {
const params = Object.fromEntries(
keys.map(key => {
const value = match.params[key];
node -v > .nvmrc
@adi518
adi518 / get_git_branch_sha.sh
Created June 25, 2019 12:04 — forked from scottwb/get_git_branch_sha.sh
Get the SHA of some git branch.
# Get the SHA of some branch. There must be a better way to do this.
git log -1 --pretty=oneline origin/somebranch | sed -E "s/^([^[:space:]]+).*/\1/"
const download = (fileName, data) => {
const blob = new Blob([data]);
const url = window.URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = fileName;
a.style = "display: none";
document.body.appendChild(a);
a.click();
a.remove();
@adi518
adi518 / download-file.js
Created May 26, 2019 21:47 — forked from zynick/download-file.js
download file ('save as') using javascript xhr
// http://stackoverflow.com/a/23797348/1150427
xhr.open('POST', url, true);
xhr.responseType = 'arraybuffer';
xhr.onload = function () {
if (this.status === 200) {
var filename = "";
var disposition = xhr.getResponseHeader('Content-Disposition');
if (disposition && disposition.indexOf('attachment') !== -1) {
var filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;
@adi518
adi518 / regexCheatsheet.js
Created January 12, 2019 19:08 — forked from sarthology/regexCheatsheet.js
A regex cheatsheet 👩🏻‍💻 (by Catherine)
let regex;
/* matching a specific string */
regex = /hello/; // looks for the string between the forward slashes (case-sensitive)... matches "hello", "hello123", "123hello123", "123hello"; doesn't match for "hell0", "Hello"
regex = /hello/i; // looks for the string between the forward slashes (case-insensitive)... matches "hello", "HelLo", "123HelLO"
regex = /hello/g; // looks for multiple occurrences of string between the forward slashes...
/* wildcards */
regex = /h.llo/; // the "." matches any one character other than a new line character... matches "hello", "hallo" but not "h\nllo"
regex = /h.*llo/; // the "*" matches any character(s) zero or more times... matches "hello", "heeeeeello", "hllo", "hwarwareallo"
@adi518
adi518 / webkit-pseudo-elements.md
Created January 9, 2019 19:31 — forked from leostratus/webkit-pseudo-elements.md
Webkit Pseudo-Element Selectors (Shadow DOM Elements)

An ongoing project to catalogue all of these sneaky, hidden, bleeding edge selectors as I prepare my JSConf EU 2012 talk.

Everything is broken up by tag, but within each the selectors aren't particularly ordered.

I have not tested/verified all of these. Have I missed some or got it wrong? Let me know. - A

A friendly reminder that you may need to set this property on your target/selected element to get the styling results you want:

-webkit-appearance:none;

@adi518
adi518 / clearfix.scss
Last active October 30, 2018 01:27
Latest Clearfix hack
// https: //stackoverflow.com/a/3805213/4106263
// https: //stackoverflow.com/questions/211383/what-methods-of-clearfix-can-i-use
// https: //github.com/h5bp/html5-boilerplate/blob/master/src/css/main.css#L169
.clearfix {
&::after,
&::before {
content: ' ';
/* 1 */
display: table;
// Compatible with Vue.js
function getElementByRef(ref, refs) {
refs = refs || this.$refs
const noRefs = !refs
if (noRefs) {
console.error(`[getElementByRef warn]: No refs found.`)
return