Skip to content

Instantly share code, notes, and snippets.

👮‍♀
git inspector

Andrew Luca iamandrewluca

👮‍♀
git inspector
Block or report user

Report or block iamandrewluca

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@iamandrewluca
iamandrewluca / exact-type.ts
Created Sep 20, 2019
Make TypeScript match types exactly
View exact-type.ts
type Exact<T, Shape> =
// Check if `T` is matching `Shape`
T extends Shape
// Does match
// Check if `T` has same keys as `Shape`
? Exclude<keyof T, keyof Shape> extends never
// `T` has same keys as `Shape`
? T
// `T` has more keys than `Shape`
: never
@iamandrewluca
iamandrewluca / this-type.ts
Created Sep 18, 2019
TypeScript `this` type
View this-type.ts
class SomeLongNameClass<This extends SomeLongNameClass<This>> {
addA(): this {
return this
}
addB(): this {
return this
}
addC(): this {
return this
}
View dynamic-return.ts
type Test = {
foo: number
returnString?: boolean
}
function test(): number
function test(arg: Omit<Test, 'returnString'>): number
function test(arg: Test & { returnString: false }): number
function test(arg: Test & { returnString: true }): string
function test(arg: Test = { foo: 2 }): number | string {
@iamandrewluca
iamandrewluca / Accordion.jsx
Last active Sep 7, 2019
Reactstrap Uncontrolled Accordion
View Accordion.jsx
import React from 'react'
import { Card, CardBody, CardHeader, Collapse, Button } from 'reactstrap'
import PropTypes from 'prop-types'
export class Accordion extends React.Component {
state = {
open: this.props.open,
}
toggleSection = (index) => () => {
@iamandrewluca
iamandrewluca / oss-tools.md
Last active Aug 9, 2019
Open source software tools
@iamandrewluca
iamandrewluca / README.md
Last active Aug 6, 2019
Grep l10n labels from project
View README.md
grep -rhosP "(?<=l10n\(\')([\w\.]+)(?=\'\))" src/
  • -r recursive in nested folders and files
  • -h don't show file names
  • -o print only matches
  • -s silent errors
  • -P activate advanced perl regex
  • (?<=l10n\(\') must start with l10n(' but don't include in match
View x.md

X_Addons_Validation::get_validation_response instant return array from end of function
X_Addons_Validation::ajax_validation comment $validator->run();
X_Addons_Updates::update comment if ( isset( $data['error'] ) ) { if

or

Add this x_product_validation_key wordpress option with any value

View custom-select.scss
/**
*
* @author: https://github.com/filamentgroup/select-css
*
*/
/* Container used for styling the custom select, the buttom class below adds the bg gradient, corners, etc. */
.custom-select {
position: relative;
display: block;
@iamandrewluca
iamandrewluca / index.js
Last active Jul 26, 2019
Open DefinitelyTyped package definitions
View index.js
const link = document.createElement('a');
const packageName = window.prompt('Package name');
if (packageName) {
link.href = 'https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/' + packageName;
} else {
link.href = 'https://github.com/DefinitelyTyped/DefinitelyTyped/';
}
link.target = '_blank';
document.body.appendChild(link);
link.click();
@iamandrewluca
iamandrewluca / index.js
Last active Jul 25, 2019
app.get as app.use
View index.js
const express = require("express");
const app = express();
const staticServe = express.static("public");
function appUse(root, middleware) {
// don't have to do magic
if (!root) {
console.log("no root");
return middleware;
}
You can’t perform that action at this time.