Skip to content

Instantly share code, notes, and snippets.

View yuvalbl's full-sized avatar

Yuval yuvalbl

  • Earth
View GitHub Profile
@yuvalbl
yuvalbl / Button.tsx
Last active October 22, 2022 08:32
React and the Missing Children
// Button.tsx
interface Props {
onClick: (event: MouseEvent<HTMLButtonElement>) => void;
children: string;
}
export const Button: FC<Props> = ({ onClick, children }) => {
return (
<button onClick={onClick}>
{children}
</button>
@yuvalbl
yuvalbl / 1_react_docs_spread.jsx
Last active June 22, 2021 19:18
react_spread_attributes
function App1() {
return <Greeting firstName="Ben" lastName="Hector" />;
}
function App2() {
const props = { firstName: 'Ben', lastName: 'Hector' };
return <Greeting {...props} />;
}
@yuvalbl
yuvalbl / 1_apollo_v3_usequery.jsx
Last active November 21, 2020 19:55
Apollo ClientV3 power ups
import { gql, useQuery } from '@apollo/client';
const GET_DOGS = gql`
query GetDogs {
dogs {
id
breed
}
}
`;
@yuvalbl
yuvalbl / text_dnd1.html
Last active October 19, 2020 08:55
Text drag and drop
<div ondragover="allowDrop(event)">
Drop here
</div>
<script>
function allowDrop(ev) {
ev.preventDefault();
}
</script>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script src="https://unpkg.com/@reactivex/rxjs@5.0.3/dist/global/Rx.js"></script>
<script src="script.js"></script>
@yuvalbl
yuvalbl / findInFiles.js
Created October 16, 2017 15:51
find in files
const findInFiles = require('find-in-files');
const fs = require('fs');
findInFiles.find('import', 'src', '.ts$')
.then(results => {
const files = Object.keys(results);
files.forEach((file) => {
let result = fs.readFileSync(file, 'utf8');
console.log(result);
@yuvalbl
yuvalbl / test_v8.js
Last active September 30, 2018 06:00
Test cases on v8
// run with :
// node --trace_deopt --allow-natives-syntax FILENAME
function adder(a, b) {
return new Function('a', 'b', 'return b%2 ? a + b : b%3 ? a - b : b%5 ? b / a : a * b')(a, b);
}
function addereval(a, b) {
return eval('b%2 ? a + b : b%3 ? a - b : b%5 ? b / a : a * b');
}