Skip to content

Instantly share code, notes, and snippets.

View izelnakri's full-sized avatar
🇺🇦
Ember.js is the best.

Izel Nakri | izelnakri.eth izelnakri

🇺🇦
Ember.js is the best.
View GitHub Profile
@izelnakri
izelnakri / nixos-x1.rst
Created August 27, 2023 17:27 — forked from akaihola/nixos-x1.rst
Installing NixOS on a Lenovo ThinkPad Carbon X1 Gen 9

Installing NixOS on a Lenovo ThinkPad Carbon X1 Gen 9

Installation media

  • Downloaded nixos-21.11/latest-nixos-gnome-x86_64-linux.iso__ from channels.nixos.org__.
  • NixOS manual instructs to create the USB stick using dd
@izelnakri
izelnakri / http-server.js
Created July 6, 2023 19:22
No-dependency HTTP Server in node.js
import fs from "node:fs";
import http from "node:http";
import path from "node:path";
import process from "node:process";
const PORT = 8000;
const STATIC_PATH = path.join(process.cwd(), "./static");
const NOT_FOUND_HTML_PATH = path.join(STATIC_PATH, "./404.html");
const MIDDLEWARE_HANDLER = async (req, res) => {
@izelnakri
izelnakri / dear-recruiter.js
Last active September 8, 2022 15:40
Running this as a local cronjob with 1h intervals
import process from "process";
import chrome from 'chrome-cookies-secure';
import Puppeteer from "puppeteer";
const HOURLY_RATE = process.env.HOURLY_RATE || 320;
const DEBUG = process.env.DEBUG;
const CHROME_PROFILE = 'Profile 2'; // Change this to your chrome profile
const DEFAULT_TIMEOUT = 3000;
const BROWSER_HEIGHT = 800;
@izelnakri
izelnakri / benchmark.js
Last active December 17, 2021 01:50
Benchmark boilerplate
import setup from "./setup-benchmark.js";
let Benchmark = setup();
Benchmark.add('RegExp#test', () => {
/o/.test('Hello World!');
});
Benchmark.add('String#indexOf', () => {
'Hello World!'.indexOf('o') > -1;
});
type RequireOnlyOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclude<keyof T, Keys>> &
{
[K in Keys]-?: Required<Pick<T, K>> & Partial<Record<Exclude<Keys, K>, undefined>>;
}[Keys];
export interface ModelRefShape {
id?: number;
uuid?: string;
[propName: string]: any;
}
let stdin = process.stdin;
stdin.setRawMode(true);
stdin.resume();
stdin.setEncoding('utf8');
let targetInputs = {};
let inputs = [];
stdin.on('data', function(key){
import { assert } from 'chai';
import { Readable, PassThrough } from 'stream';
import * as readline from 'readline';
import { spawn } from 'child_process';
// Adaptor for Node 10 to adapt readline streams for async iteration.
// (via https://medium.com/@wietsevenema/node-js-using-for-await-to-read-lines-from-a-file-ead1f4dd8c6f)
function readLines(input: Readable): Readable {
let output = new PassThrough({ objectMode: true });
let lines = readline.createInterface({ input });
@izelnakri
izelnakri / devtools.js
Last active February 9, 2021 10:15
This optionally exposes the developer to some global utility functions on google chrome dev console: routes(), route(), model(), service('$serviceName') etc.
import Service from '@ember/service';
import ENV from 'frontend/config/environment';
import { getOwner } from '@ember/application';
export default class DevToolService extends Service {
owner = getOwner(this);
constructor() {
super(...arguments);
@izelnakri
izelnakri / changeset-and-query.ts
Last active February 25, 2021 00:57
Ember-data + Memserver + Ecto(ORM) API unification && Memserver + Express.js API unification
import { from, where, join, leftJoin, innerJoin } from 'memserver/query';
import { cast, validat cast, validateRequired, validateFormat, validateLength, uniqueConstraint, foreignKeyConstraint } from 'memserver/changeset';
let userFirstNames = User
|> where('u', 'u.id < 200') // 'm' because there could be multiple model references on |> sql joins()
|> select('u', 'u.first_name')
|> Repo.all
// or maybe some API like this as well: https://apidock.com/rails/ActiveRecord/QueryMethods/where
// or direct memserver like API User.findBy({});