Skip to content

Instantly share code, notes, and snippets.

@T1T4N
T1T4N / generate-xcode-compilation-database.md
Last active May 13, 2024 02:01
Generate a JSON Compilation Database from an Xcode project

Introduction

A JSON compilation database is a very handy output format which is parsed and used by many development tools. Unfortunately for us Apple Developers, it is not straightforward to generate one from within Xcode, as it is (probably) not Apple's priority and therefore there is no toggle/switch/setting that can be easily enabled to get this information.

There is however a solution, thanks to Apple using Clang/LLVM as their main toolchain.

Implementation

The standard way to generate this with clang would be to use the -MJ flag and give it a file name that typically corresponds to the input file. Using this flag indirectly through Xcode is hard, given that we're not aware of all the other arguments when a compiler call is executed.

However, there is a second hidden/badly documented LLVM flag: -gen-cdb-fragment-path - it is implemented in terms of -MJ and has the same functionality, but it's argument in contrast is an output directory.

@calebrob6
calebrob6 / running_stats_in_torch.py
Last active May 13, 2024 02:01
A class for computing online mean and variance of multi-dimensional arrays in PyTorch (i.e. for computing per-channel stats over large image datasets).
import torch
class RunningStatsButFast(torch.nn.Module):
def __init__(self, shape, dims):
"""Initializes the RunningStatsButFast method.
A PyTorch module that can be put on the GPU and calculate the multidimensional
mean and variance of inputs online in a numerically stable way. This is useful
for calculating the channel-wise mean and variance of a big dataset because you
don't have to load the entire dataset into memory.
@shamil
shamil / mount_qcow2.md
Last active May 13, 2024 02:01
How to mount a qcow2 disk image

How to mount a qcow2 disk image

This is a quick guide to mounting a qcow2 disk images on your host server. This is useful to reset passwords, edit files, or recover something without the virtual machine running.

Step 1 - Enable NBD on the Host

modprobe nbd max_part=8
@ABelliqueux
ABelliqueux / linux_ps2.md
Last active May 13, 2024 01:56
How to install Linux on the Playstation 2

Adapted to gist from https://unix.stackexchange.com/questions/344225/how-to-install-linux-on-the-playstation-2
Credits to Alison E.E.

Preambule

Looking to learn about game development? Are you a Linux enthusiast looking to test the claim that "Linux runs on everything"? Perhaps you are a software developer who is looking to release for multiple architectures, and you don't have another MIPS Little Endian machine on-hand for testing your programme. Whatever your situation there are a surprising number of reasons to install Linux on a Playstation 2, even sixteen years after it's release (boy do I feel old all of a sudden.), yet an equally surprising lack of documentation about it or how to install it.

Now don't get me wrong, if you want to use the original Sony Linux Kit, or one of it's updated open source releases on a fat PS2 with a network adapter and an IDE hard disk you can find plenty of info. However th

@joshschmelzle
joshschmelzle / remap-capslock-to-control-win10.md
Last active May 13, 2024 01:55
Remap Caps Lock to Control on Windows 10

Ways to remap caps lock to control on Windows 10

These methods in this gist worked for me on my U.S.-based keyboard layouts. I am unsure about other layouts. If you have problems, revert your changes; delete the registry key you created (and reboot).

Update: you should probably scroll down to approach 4 where I suggest using Microsoft PowerToys Keyboard Manager.

Approach 1. Manually through regedit

Navigate to and create a new binary value in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout named Scancode Map.

@aurbano
aurbano / timeBetween.php
Last active May 13, 2024 01:48
Display the time between two dates in a human readable format (i.e. 3 seconds, 4 days, 1 week... )
<?php
/**
* Calculate the elapsed time between two timestamps
* and display in a pretty human way.
* @param integer $start Initial timestamp
* @param integer $end Final timestamp, set to -1 for current time.
* @return string Formatted elapsed time.
*/
function timeBetween($start, $end=-1){
if($end < 0) $end = time();
@janegilring
janegilring / profile.ps1
Last active May 13, 2024 01:45
PowerShell profile used cross-platform (Linux, macOS, Windows)
#Requires -Version 7
# Version 1.3.7
# Cross-platform PowerShell profile based on https://devblogs.microsoft.com/powershell/optimizing-your-profile/
# check if newer version
$gistUrl = 'https://api.github.com/gists/a4e366e6b01f0b70eae90557dfc9d21d'
$latestVersionFile = [System.IO.Path]::Combine("$HOME", '.latest_profile_version')
$versionRegEx = '# Version (?<version>\d+\.\d+\.\d+)'
@aamiaa
aamiaa / CompleteDiscordQuest.md
Last active May 13, 2024 01:45
Complete Recent Discord Quest

Complete Recent Discord Quest

Note

This no longer works in browser!

Note

This no longer works if you're alone in vc! Somebody else has to join you!

How to use this script:

  1. Accept the quest under User Settings -> Gift Inventory
@ishad0w
ishad0w / sources.list
Last active May 13, 2024 01:45
Debian 10 (Buster) -- Full sources.list
deb http://deb.debian.org/debian buster main contrib non-free
deb-src http://deb.debian.org/debian buster main contrib non-free
deb http://deb.debian.org/debian buster-updates main contrib non-free
deb-src http://deb.debian.org/debian buster-updates main contrib non-free
deb http://deb.debian.org/debian buster-backports main contrib non-free
deb-src http://deb.debian.org/debian buster-backports main contrib non-free
deb http://security.debian.org/debian-security/ buster/updates main contrib non-free
@greymd
greymd / sudo新一.md
Last active May 13, 2024 01:45
sudo新一

 オレは高校生シェル芸人 sudo 新一。幼馴染で同級生の more 利蘭と遊園地に遊びに行って、黒ずくめの男の怪しげな rm -rf / 現場を目撃した。端末をみるのに夢中になっていた俺は、背後から近づいてきたもう1人の --no-preserve-root オプションに気づかなかった。 俺はその男に毒薬を飲まされ、目が覚めたら・・・ OS のプリインストールから除かれてしまっていた!

sudo がまだ $PATH に残っていると奴らにバレたら、また命を狙われ、他のコマンドにも危害が及ぶ』

 上田博士の助言で正体を隠すことにした俺は、 which に名前を聞かれて、とっさに『gnuplot』と名乗り、奴らの情報をつかむために、父親がシェル芸人をやっている蘭の $HOME に転がり込んだ。ところが、このおっちゃん・・・とんだヘボシェル芸人で、見かねた俺はおっちゃんになりかわり、持ち前の権限昇格能力で、次々と難タスクを解決してきた。おかげで、おっちゃんは今や世間に名を知られた名エンジニア、俺はといえばシェル芸 bot のおもちゃに逆戻り。クラスメートの convertojichattextimg にお絵かきコマンドと誤解され少年ワンライナーお絵かき団を結成させられる始末。

 ではここで、博士が作ってくれたメカを紹介しよう。最初は時計型麻酔 kill 。ふたについた照準器にあわせてエンターを押せば、麻酔シグナルが飛び出し、プロセスを瞬時に sleep させることができる。 次に、蝶ネクタイ型 banner 。裏についているダイヤルを調整すれば、ありとあらゆる大きさのメッセージを標準出力できる。必殺のアイテムなら fork 力増強シューズ。電気と磁力で足を刺激し、 :(){ :|:&amp; };: でプロセステーブ