Skip to content

Instantly share code, notes, and snippets.

View bahmutov's full-sized avatar
🍺
on a roll

Gleb Bahmutov bahmutov

🍺
on a roll
View GitHub Profile
@bahmutov
bahmutov / Docker shell commands.sh
Last active February 9, 2024 07:55
A personal cheat sheet for running local Node project in a Docker container
# See list of docker virtual machines on the local box
$ docker-machine ls
NAME ACTIVE URL STATE URL SWARM DOCKER ERRORS
default * virtualbox Running tcp://192.168.99.100:2376 v1.9.1
# Note the host URL 192.168.99.100 - it will be used later!
# Build an image from current folder under given image name
$ docker build -t gleb/demo-app .
@bahmutov
bahmutov / README.md
Last active October 4, 2023 08:35
Single command to run Node with local file access

Goal: run a simple NodeJS application inside a Docker container

Subgoal: give it access to local files.

docker run -it --rm --name example -v "$PWD":/usr/src/app -w /usr/src/app node:5-slim node index.js

output:

@bahmutov
bahmutov / README.md
Last active July 11, 2022 13:03
Trying Redis in Docker + as-a

Goal: try redis inside a Docker container

Run Redis Docker image

  1. Open docker terminal
  • displays docker is configured to use the default machine with IP 192.168.99.100
  1. Start redis:alpine prebuilt container from docker hub.
  • docker run --name redis -p 6379:6379 -d redis:alpine
  • the "alpine" image is very slim (5MB!)
  • the running container binds the internal port 6379 to the "outside" world port with same number
@bahmutov
bahmutov / index.js
Created August 10, 2017 15:37
Kleisli composition example (JSON parsing + deep property)
// following along https://medium.com/@luijar/kliesli-compositions-in-javascript-7e1a7218f0c4
const R = require('ramda')
const Maybe = require('ramda-fantasy').Maybe
// parse JSON string into object
// parse :: String -> Object | Null
function parse(s) {
try {
return JSON.parse(s)
} catch (e) {
it('until the number 7 appears', () => {
const checkAndReload = () => {
// get the element's text, convert into a number
cy.get('#result').should('not.be.empty')
.invoke('text').then(parseInt)
.then((number) => {
// if the expected number is found
// stop adding any more commands
if (number === 7) {
cy.log('lucky **7**')
@bahmutov
bahmutov / ping-spec.js
Created February 21, 2021 19:08
Example anchor ping stub in Cypress
```js
/// <reference types="Cypress" />
describe('intercept', () => {
it('stubs anchor ping', () => {
cy.visit('/')
cy.intercept({
method: 'POST',
pathname: '/track'
}, {}).as('ping')
cy.get('a[ping]').click()
@bahmutov
bahmutov / keybase.md
Created August 4, 2020 23:53
keybase

Keybase proof

I hereby claim:

  • I am bahmutov on github.
  • I am glebb (https://keybase.io/glebb) on keybase.
  • I have a public key ASBM0WBon-OfVjLsNOuqvrPMbR0HNkjc9zdg42Sxp-K3kQo

To claim this, I am signing this object:

@bahmutov
bahmutov / bio.md
Last active January 28, 2020 01:35
Performance measurement using Chrome DevTools code snippets

Gleb Bahmutov is JavaScript ninja, image processing expert and software quality fanatic. After receiving a PhD in computer science from Purdue University, Gleb worked on laser scanners, 3D reconstruction, and panorama-based virtual tours at EveryScape. Later Gleb switched to writing browser data visualization software at MathWorks. After a year, Gleb went back to the startup environment and developed software quality analysis tools at uTest (now Applause). Today Gleb is developing real-time financial analysis tools at Kensho. He blogs about software development topics at http://bahmutov.calepin.co/ and links his projects at http://glebbahmutov.com/. You can follow him and his work @bahmutov

@bahmutov
bahmutov / README.md
Created July 24, 2019 19:43
Looking at wallclock vs frame timestamp

Printing wallclock timestamps and frame timestamps (since common start)

cypress:server:video 1.3989999294281006 frame 1.326711893081665 received screencastFrame +0ms
  cypress:server:video 1.5299999713897705 frame 1.4792709350585938 received screencastFrame +131ms
  cypress:server:video 2.922999858856201 frame 2.340052843093872 received screencastFrame +1s
Browserslist: caniuse-lite is outdated. Please run next command `npm update caniuse-lite browserslist`
  cypress:server:video 4.042999982833862 frame 2.4192519187927246 received screencastFrame +1s
  cypress:server:video 4.049000024795532 frame 2.584810972213745 received screencastFrame +7ms

@bahmutov
bahmutov / README.md
Last active September 27, 2018 00:55
Loading multiple service workers

Imagine I want to separate caching for offline support from other features. I would load first service worker to cache index.html and static resources in /static and would load second service worker to do other things.

<script>
    if ('serviceWorker' in navigator) {
      console.log('page is registering two service workers')
      // one.js should cache index.html and /static folder
 navigator.serviceWorker.register('one.js', {scope: './'})