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
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 / 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
@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;
}
View nested-object-flatten-keys.js
const theObject = {
nested1: {
key1: "value1",
nested2: {
key2: "value2"
}
},
key3: "value3",
key4: ["test", "test1"]
};
@iamandrewluca
iamandrewluca / spy-typing.js
Created May 15, 2019
This script will spy the page for what you type and when will match what you find will inform
View spy-typing.js
function spy(regexp, callback) {
let state = "";
document.addEventListener("keydown", function(e) {
state += e.key;
console.log(e.key);
const match = state.match(regexp);
if (match) {
callback(match[0]);
state = "";
}
@iamandrewluca
iamandrewluca / mailto-confirm.js
Last active Mar 26, 2019
Will prompt to confirm mailto links.
View mailto-confirm.js
Array.from(document.querySelectorAll('[href^="mailto:"]')).forEach(a => {
a.addEventListener('click', function(e) {
if (!confirm('Are you sure?')) {
e.preventDefault()
}
})
})
@iamandrewluca
iamandrewluca / array-operator-overload.cpp
Created Mar 20, 2019
Supraincarcarea operatorului paranteze patrate de 2 ori in C++ creind o matrice.
View array-operator-overload.cpp
/**
Titlu: Supraincarcarea operatorului [][] in C++ creind o matrice.
Autor: Luca Andrei
Ideone: http://ideone.com/y8Km37
Descriere: De fapt operatorul [][] nu poate fi supraincarcat,
deoarece el nu este operator )), ma contrazic pe mine ce am scris in titlu ).
De fapt aici sunt doi operatori []. Pentru a "supraincarca" [][], avem nevoie
sa cream 2 clase, si pentru fiecare in parte sa supraincarcam [].
Urmariti exemplul de mai jos pentru lamurire.
/**/
@iamandrewluca
iamandrewluca / array-alloc.c
Created Mar 20, 2019
Alocarea dinamica a unui tablou bidimensional
View array-alloc.c
#include <stdio.h>
#include <conio2.h>
#include <stdlib.h>
int **a, n, m, i, j;
int main(void){
// citesti numarul de linii
printf("Dati numarul de linii >> ");
You can’t perform that action at this time.