Skip to content

Instantly share code, notes, and snippets.

@wojteklu
wojteklu / clean_code.md
Last active May 10, 2024 10:03
Summary of 'Clean code' by Robert C. Martin

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

@dennissergeev
dennissergeev / xgrid_utils.py
Last active May 10, 2024 10:00
Calculate a spatial mean of xarray's DataArray
# -*- coding: utf-8 -*-
"""Operations on cartesian geographical grid."""
import numpy as np
EARTH_RADIUS = 6371000.0 # m
def _guess_bounds(points, bound_position=0.5):
"""
Guess bounds of grid cells.
@archan937
archan937 / setup-dnsmasq.sh
Last active May 10, 2024 10:00
Point *.test to 127.0.0.1 using DNSMasq and NetworkManager on Ubuntu
#!/bin/bash
# Usage:
#
# curl -sL https://gist.githubusercontent.com/archan937/d35deef3b1f2b5522dd4b8f397038d27/raw/setup-dnsmasq.sh | sudo bash
#
DOMAIN=".test"
ensure_ping() {
@adamjohnson
adamjohnson / publickey-git-error.markdown
Last active May 10, 2024 10:00
Fix "Permission denied (publickey)" error when pushing with Git

"Help, I keep getting a 'Permission Denied (publickey)' error when I push!"

This means, on your local machine, you haven't made any SSH keys. Not to worry. Here's how to fix:

  1. Open git bash (Use the Windows search. To find it, type "git bash") or the Mac Terminal. Pro Tip: You can use any *nix based command prompt (but not the default Windows Command Prompt!)
  2. Type cd ~/.ssh. This will take you to the root directory for Git (Likely C:\Users\[YOUR-USER-NAME]\.ssh\ on Windows)
  3. Within the .ssh folder, there should be these two files: id_rsa and id_rsa.pub. These are the files that tell your computer how to communicate with GitHub, BitBucket, or any other Git based service. Type ls to see a directory listing. If those two files don't show up, proceed to the next step. NOTE: Your SSH keys must be named id_rsa and id_rsa.pub in order for Git, GitHub, and BitBucket to recognize them by default.
  4. To create the SSH keys, type ssh-keygen -t rsa -C "your_email@example.com". Th
@Rahandi
Rahandi / config.php
Created May 1, 2018 10:51
pendaftaran-siswa
<?php
$server = "localhost";
$user = "root";
$password = "";
$nama_database = "pendaftaran_siswa";
$db = mysqli_connect($server, $user, $password, $nama_database);
if( !$db ){
die("Gagal terhubung dengan database: " . mysqli_connect_error());
@akwodkiewicz
akwodkiewicz / resolver.js
Created May 10, 2024 08:59
Custom Jest resolver to solve "dual state" issues with self-referencing and subpath imports in TypeScript projects
/**
* This resolver forces Jest to look at a *custom* `"jest"` condition in `package.json#exports`.
*
* Whenever you use self-referencing imports or subpath imports in the source code (or tests)
* the default behaviour of Jest is to go to the package's manifest for information, and resolve
* the import by choosing one of the conditions that are used by Node ("node", "default", etc.).
*
* The issue is that "node"/"default" usually points to transpiled `.js` files, whereas if you decide to
* run the tests on the `.ts` source code (with the help of a transformer such as ts-jest or @swc/jest),
* you need Jest to **only** load the `.ts` files. Otherwise, you end up with duplicated classes,
@pmenke-de
pmenke-de / README.md
Last active May 10, 2024 09:54 — forked from chpatrick/nix-cmake
Using CLion with Nix

let's say you have a C++ project in Nix that you want to work on with CLion so that the nix dependencies are available.

  1. create a .nix utility directory in your project directory.
  2. put the below nix-run.sh and nix-cmake.sh in the .nix directory.
  3. in the .nix directory create symlinks for make, gcc, g++ - and maybe more tools, that need to have the nix dependencies and build tools available - and point them to nix-run.sh
  4. then, in Settings -> Build, Execution, Deployment -> Toolchains set CMake to the path to nix-cmake.sh and point all other build tools to the symlinks you've created.
@MarkWarneke
MarkWarneke / Makefile
Created June 18, 2020 12:25
Makefile for python code
# Makefile for python code
#
# > make help
#
# The following commands can be used.
#
# init: sets up environment and installs requirements
# install: Installs development requirments
# format: Formats the code with autopep8
# lint: Runs flake8 on src, exit if critical rules are broken
@Strus
Strus / clangd.md
Last active May 10, 2024 09:49
How to use clangd C/C++ LSP in any project

How to use clangd C/C++ LSP in any project

tl;dr: If you want to just know the method, skip to How to section

Clangd is a state-of-the-art C/C++ LSP that can be used in every popular text editors like Neovim, Emacs or VS Code. Even CLion uses clangd under the hood. Unfortunately, clangd requires compile_commands.json to work, and the only way to painlessly generate it is to use CMake.

But what if I tell you you can quickly hack your way around that, and generate compile_commands.json for any project, no matter how compilcated? I have used that way at work for years, originaly because I used CLion which supported only CMake projects - but now I use that method succesfully with clangd and Neovim.

Method summary

Basically what we need to achieve is to create a CMake file that will generate a compile_commands.json file with information about:

@sebkln
sebkln / RequestMiddlewares.php
Created January 6, 2024 15:48
Middleware for web manifest in TYPO3 v12. Adjusted version of the solution provided by Kevin Appelt in TYPO3 Slack: https://typo3.slack.com/archives/C025BQLFA/p1680299950579649
<?php
return [
'frontend' => [
'yourvendor/webmanifest' => [
'target' => \YourVendor\Sitepackage\Middleware\Webmanifest::class,
'before' => [
'typo3/cms-frontend/page-resolver',
],
'after' => [