Skip to content

Instantly share code, notes, and snippets.

// здесь нужна только сеть
const net = require("net");
const client = new net.Socket();
// «звоним» на номер 127.0.0.1:1234
// (да, это мой номер, но для целей данной статьи подходит)
client.connect(1234, "127.0.0.1", () => {
console.log("подключаемся к серверу..");
// говорим в трубку, что мы хотим сказать
@askhat
askhat / client.js
Created February 6, 2025 17:51
unix socket js example
const net = require("net"); // тут только сеть, работать непосредственно с файлом мы не будем
const socketPath = "/tmp/my_awesome.sock";
const client = net.createConnection({path: socketPath}, () => {
console.log("подключаемся к серверу..");
// пишем нашему серверу, через сеть, в его файл сокета
client.write("salem baurym"); // сообщение стандартизовано нашим протоколом прикладного уровня ^_^
});
#lang racket
; SICP exercise 1.3 (page 27)
; Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers.
(define (sum-of-squares-of-two-largest-args a b c)
(cond ((and (< a b) (< a c)) (+ (* b b) (* c c)))
((and (< b a) (< b c)) (+ (* a a) (* c c)))
((and (< c a) (< c b)) (+ (* a a) (* b b)))))
import {assertEquals} from "https://deno.land/std@0.209.0/assert/mod.ts";
class LinkedList<T> {
#value: T;
#next?: LinkedList<T>;
constructor(value: T, next?: LinkedList<T>) {
this.#value = value;
this.#next = next;
}
@askhat
askhat / hex-to-rgb.js
Created November 23, 2022 14:03
Color fns
function hexToRgb(hex) {
let m = hex.match(/^#?([\da-f]{2})([\da-f]{2})([\da-f]{2})$/i);
let r = parseInt(m[1], 16);
let g = parseInt(m[2], 16);
let b = parseInt(m[3], 16);
return {r, g, b};
}
@askhat
askhat / word-stat.rb
Created September 12, 2020 19:15
Word Stat
class String
def /(s)
self + "/" + s
end
end
CWD ,= ARGV[0]
raise ArgumentError unless Dir.exists? CWD
STOP_WORDS = %w( this var let const class function true false require process )
@askhat
askhat / gems.rb
Created March 30, 2020 11:55
Appium Upsream Sync
source "https://rubygems.org"
gem "whirly"
gem "colorize"
gem "tty-table"
gem "tty-prompt"
group :development do
gem "pry"
end
@askhat
askhat / User.test.ts
Created January 21, 2020 08:34
MobX store for OIDC Client
import { User } from './User'
import { UserManager } from 'oidc-client'
const mockGetUser = jest.fn()
const mockSigninRedirect = jest.fn()
const mockSigninRedirectCallback = jest.fn()
const mockSignoutRedirect = jest.fn()
const mockSignoutRedirectCallback = jest.fn()
jest.mock('oidc-client', () => ({
@askhat
askhat / usePouch.ts
Created January 7, 2020 18:11
usePouch.ts
import PouchDB from "pouchdb";
import { useState, useEffect } from "react";
let dbPool = new Map<string, PouchDB.Database>();
let resolveOrCreateDb = <T>(dbName: string, dbPrefix = "sfpic_") => {
let db = dbPool.get(dbName);
if (db instanceof PouchDB) return db as PouchDB.Database<T>;
db = new PouchDB<T>(dbPrefix + dbName);
dbPool.set(dbName, db);
@askhat
askhat / prepare-commit-msg
Last active June 28, 2018 11:23
Insert ticket number into each commit message
#!/usr/bin/env node
const fs = require('fs')
const { exec } = require('child_process')
const COMMIT_EDITMSG = process.argv[2]
exec('git symbolic-ref --short HEAD', (err, branch) => {
if (err) throw err