Skip to content

Instantly share code, notes, and snippets.

@galabra
galabra / empatheticCode.js
Created January 8, 2021 11:36
These three versions of equivalent code demonstrates how code should be self-explainable
dataArray.reduce((a, b) => [...a,
...(b.data && b.data.isImportant && b.data.value ? [b.data.value] : [])
], []);
/**
* Thwe horrific JavaScript snippet above is equivalent to the following
*/
dataArray
.filter((x) => x.data && x.data.isImportant && x.data.value)
@galabra
galabra / WordsDivisions.js
Created April 17, 2019 22:44
Divide a list of strings by specific characters combinations
const arr = [/* The list of valid words */]
const regex = /(אמת|ג|דעם|ום|ז(י|ך|נ|ץ)?|טב|י(ז|ן|ץ)?|כ|ךק|ל|מ(חל|רצ)|נ(ז|ץ|ר)?|ן(ך|נ)?|פה|ף(ז|י|ך|נ|ץ)?|צק|ץ(ז|י)?|ק(י|ן|ף)?|ר|שס)+?/g;
function divideWord(word) {
let ans = '';
let prefix = '';
let match = regex.exec(word);
while (match !== null) {
ans += prefix + match[1];
@galabra
galabra / package.json
Created October 25, 2018 17:49
Customizing package.json
"build-css": "node-sass-chokidar --include-path ./src src/ -o src/"
// turns into:
"build-css": "node-sass-chokidar --include-path ./src src/ -o src/ && node-sass-chokidar --include-path ./public/css public/css/ -o public/css/"
@galabra
galabra / OptimizedLandingPage.jsx
Last active October 25, 2018 17:40
An example for an optimized landing page component
import 'css/aboveTheFoldLandingPage.css';
// Now only this file was blocking the rendering process
class LandingPage extends Component {
render() {
return <div className="landingPage">
<div className="above">
{/* I'm above the fold,
Therefore I need to load first. */}
</div>
@galabra
galabra / LandingPage.jsx
Last active October 25, 2018 17:37
An example for a landing page component
import 'css/wholeLandingPage.css';
import 'css/bootstrap.min.css';
class LandingPage extends Component {
render() {
return <div className="landingPage">
<div className="above">
{/* I'm above the fold,
Therefore I need to load first. */}
</div>
.LC0:
.string "%d\n"
main:
push rbp
mov rbp, rsp
sub rsp, 16
mov dword[rbp-4], 1
jmp .L2
.L3:
mov eax, dword[rbp-4]
#include <stdio.h>
int main() {
char* words[3] = {"apple", "orange", "banana"};
for(int i = 1; i < 4; i ++) {
printf("%d. %s\n", i, words[i - 1]);
}
return 0;
}
public class JavaExample {
public static void main(String[] args) {
String[] words = {"apple", "orange", "banana"};
for(int i = 1; i < 4; i ++) {
String toPrint = i + ". " + words[i - 1];
System.out.println(toPrint);
}
}
}
words = ["apple", "orange", "banana"]
for i in range (1,4):
to_print = str(i) + ". " + words[i - 1]
print(to_print)