Skip to content

Instantly share code, notes, and snippets.

@dmmeteo
dmmeteo / 1.srp.py
Last active May 8, 2024 10:27
SOLID Principles explained in Python with examples.
"""
Single Responsibility Principle
“…You had one job” — Loki to Skurge in Thor: Ragnarok
A class should have only one job.
If a class has more than one responsibility, it becomes coupled.
A change to one responsibility results to modification of the other responsibility.
"""
class Animal:
def __init__(self, name: str):
@yoshoku
yoshoku / foo.cc
Created April 23, 2022 10:54
console.log with node-addon-api
#include <napi.h>
class Foo : public Napi::ObjectWrap<Foo> {
public:
// ...
Napi::Value foo(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::Function consoleLog = env.Global().Get("console").As<Napi::Object>().Get("log").As<Napi::Function>();
consoleLog.Call({ Napi::String::New(env, "Hello, World.") });
@o11c
o11c / every-vm-tutorial-you-ever-studied-is-wrong.md
Last active May 8, 2024 10:26
Every VM tutorial you ever studied is wrong (and other compiler/interpreter-related knowledge)

Note: this was originally several Reddit posts, chained and linked. But now that Reddit is dying I've finally moved them out. Sorry about the mess.


URL: https://www.reddit.com/r/ProgrammingLanguages/comments/up206c/stack_machines_for_compilers/i8ikupw/ Summary: stack-based vs register-based in general.

There are a wide variety of machines that can be described as "stack-based" or "register-based", but not all of them are practical. And there are a lot of other decisions that affect that practicality (do variables have names or only address/indexes? fixed-width or variable-width instructions? are you interpreting the bytecode (and if so, are you using machine stack frames?) or turning it into machine code? how many registers are there, and how many are special? how do you represent multiple types of variable? how many scopes are there(various kinds of global, local, member, ...)? how much effort/complexity can you afford to put into your machine? etc.)

  • a pure stack VM can only access the top elemen
@asheroto
asheroto / README.md
Last active May 8, 2024 10:23
Nextcloud - Show gallery view by default with public / sharing / shared folders

Nextcloud - Show gallery view by default with public / sharing / shared folders

This will automatically switch a public or shared folder to gallery view when loading.

This only works on public or shared folders on Nextcloud and will not affect normal folders viewed under your user account.

Tested and working on Nextcloud 27+.

How to Configure

  1. Open core/js/public/publicpage.js.
@sindresorhus
sindresorhus / esm-package.md
Last active May 8, 2024 10:22
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.
@patrickmatte
patrickmatte / gist:ed2ae277172c0c5d084a9e3e733bb415
Last active May 8, 2024 10:20
CSS easing methods based on Robert Penner's, as accurate as possible to do with cubic-bezier
$easeLinear: cubic-bezier(0, 0, 1, 1);
$easeSineInOut: cubic-bezier(0.37, 0, 0.63, 1);
$easeSineIn: cubic-bezier(0.12, 0, 0.39, 0);
$easeSineOut: cubic-bezier(0.61, 1, 0.88, 1);
$easeQuadraticInOut: cubic-bezier(0.45, 0, 0.55, 1);
$easeQuadraticIn: cubic-bezier(0.11, 0, 0.5, 0);
$easeQuadraticOut: cubic-bezier(0.5, 1, 0.89, 1);
$easeCubicInOut: cubic-bezier(0.65, 0, 0.35, 1);
$easeCubicIn: cubic-bezier(0.32, 0, 0.67, 0);
$easeCubicOut: cubic-bezier(0.33, 1, 0.68, 1);
@joshbuchea
joshbuchea / semantic-commit-messages.md
Last active May 8, 2024 10:18
Semantic Commit Messages

Semantic Commit Messages

See how a minor change to your commit message style can make you a better programmer.

Format: <type>(<scope>): <subject>

<scope> is optional

Example

@upsidedwn
upsidedwn / Deobfuscator.cs
Created July 13, 2023 10:40
Custom deobfuscator template for de4dot
using System;
using System.Linq;
using System.Collections.Generic;
using dnlib.DotNet;
using de4dot.blocks;
using de4dot.code.AssemblyClient;
using dnlib.DotNet.Emit;
namespace de4dot.code.deobfuscators.SolarMaker_Malware {
public class DeobfuscatorInfo : DeobfuscatorInfoBase {