Skip to content

Instantly share code, notes, and snippets.

View 3p3r's full-sized avatar
🥦
farming...

Sepehr Laal 3p3r

🥦
farming...
View GitHub Profile
@mraleph
mraleph / gist:3397008
Created August 19, 2012 18:48
simple and incomplete explanation of V8 strings

There are two types (actually more, but for the problem at hand only these two are important):

  • flat strings are immutable arrays of characters

  • cons strings are pairs of strings, result of concatenation.

If you concat a and b you get a cons-string (a, b) that represents result of concatenation. If you later concat d to that you get another cons-string ((a, b), d).

Indexing into such a "tree-like" string is not O(1) so to make it faster V8 flattens the string when you index: copies all characters into a flat string.

@mneil
mneil / kioskmode.bat
Created February 15, 2016 19:56
Kill chrome and open a new page in kiosk mode
taskkill /F /IM Chrome.exe /T
### Open a local index.html file in the same directory as this batch file
# start chrome --kiosk --profile-directory=Default --app="%~dp0/index.html"
### Open a website URL
start chrome --kiosk --profile-directory=Default --app="http://google.com"
@kisenka
kisenka / inmemory-webpack-compiler.js
Last active April 15, 2023 15:09
Webpack in-memory filesystem
var webpack = require('webpack');
var MemoryFS = require('memory-fs');
var SingleEntryDependency = require('webpack/lib/dependencies/SingleEntryDependency');
var fs = new MemoryFS();
fs.mkdirpSync('/src');
fs.writeFileSync('/src/app.js', 'require("./dep.js")', 'utf-8');
fs.writeFileSync('/src/dep.js', 'module.exports = function(msg){console.log(msg)}', 'utf-8');
fs.writeFileSync('/src/extra-entry.js', 'require("./dep.js")', 'utf-8');
@jlgerber
jlgerber / CMakeLists.txt
Last active May 21, 2024 20:28
cmake - handling executable and library with same name
# Lets say we want to add a library and an executable, both with the same name.
# In this example, it is resman
add_library(resman ${src_cpps} ${src_hpps} )
target_link_libraries(resman ${Boost_LIBRARIES} ${LIBYAML} ${LIBFMT})
#
# Add resman executable
#
# We call the executable resman-bin
add_executable(resman-bin main.cpp )
@mneil
mneil / conftest.py
Created November 24, 2020 21:28
Patch boto3 to avoid credentials errors and real API calls during unit tests.
'''
Unit test setup automatically called
'''
from unittest import mock
import pytest
# Fixture, autouse
@pytest.fixture(scope='session', autouse=True)
def patch_boto3(request):
@sindresorhus
sindresorhus / esm-package.md
Last active July 24, 2024 08:34
Pure ESM package

Pure ESM package

The package that linked you here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.