Skip to content

Instantly share code, notes, and snippets.

View ainar-g's full-sized avatar

Ainar Garipov ainar-g

View GitHub Profile
@thetredev
thetredev / remove-snap-from-ubuntu.md
Last active December 6, 2024 10:43
Remove snap from Ubuntu

Remove snap from Ubuntu

Tested with:

  • Ubuntu Desktop 22.04.2
  • Ubuntu Server 22.04.2

Both are VirtualBox VMs on my Void Linux host. Both have been installed using the following options:

  • Normal installation (not minimal), to ensure it's fully bloated
  • With third party drivers

After the install, sudo apt update and sudo apt full-upgrade have been applied. A reboot was done next.

@fay59
fay59 / Quirks of C.md
Last active November 3, 2025 03:10
Quirks of C

Here's a list of mildly interesting things about the C language that I learned mostly by consuming Clang's ASTs. Although surprises are getting sparser, I might continue to update this document over time.

There are many more mildly interesting features of C++, but the language is literally known for being weird, whereas C is usually considered smaller and simpler, so this is (almost) only about C.

1. Combined type and variable/field declaration, inside a struct scope [https://godbolt.org/g/Rh94Go]

struct foo {
   struct bar {
 int x;
@winksaville
winksaville / Setup-git-send-email.md
Created March 20, 2018 18:25
Setup git send-email using git credentials

Setup git send-email: following these instructions I had some problems. But the following worked:

  • I’m using 2-factor auth on my gmail account so I had to get a “app-password”, see google documentation
  • Modify the global/local .gitconfig file with a sendemail section: [sendemail] smtpEncryption = tls smtpServer = smtp.gmail.com smtpUser = wink@saville.com smtpServerPort = 587
  • Also add a credential section with a helper.store entry:
@shafik
shafik / WhatIsStrictAliasingAndWhyDoWeCare.md
Last active December 3, 2025 17:13
What is Strict Aliasing and Why do we Care?

What is the Strict Aliasing Rule and Why do we care?

(OR Type Punning, Undefined Behavior and Alignment, Oh My!)

What is strict aliasing? First we will describe what is aliasing and then we can learn what being strict about it means.

In C and C++ aliasing has to do with what expression types we are allowed to access stored values through. In both C and C++ the standard specifies which expression types are allowed to alias which types. The compiler and optimizer are allowed to assume we follow the aliasing rules strictly, hence the term strict aliasing rule. If we attempt to access a value using a type not allowed it is classified as undefined behavior(UB). Once we have undefined behavior all bets are off, the results of our program are no longer reliable.

Unfortunately with strict aliasing violations, we will often obtain the results we expect, leaving the possibility the a future version of a compiler with a new optimization will break code we th

@davidbirdsong
davidbirdsong / tls_byte_buffer
Created May 3, 2016 21:17
tls allocations
[david@sjc1-b4-8 ~]$ go tool pprof $HOME/bin/hwy-fetcher http://localhost:6060/debug/pprof/heap
Fetching profile from http://localhost:6060/debug/pprof/heap
Saved profile in /home/david/pprof/pprof.hwy-fetcher.localhost:6060.inuse_objects.inuse_space.062.pb.gz
Entering interactive mode (type "help" for commands)
(pprof) top
12612.08MB of 14824.44MB total (85.08%)
Dropped 799 nodes (cum <= 74.12MB)
Showing top 10 nodes out of 87 (cum >= 201.56MB)
flat flat% sum% cum cum%
6202.85MB 41.84% 41.84% 6202.85MB 41.84% crypto/tls.(*block).reserve
@brenopolanski
brenopolanski / install-firefox-nightly.md
Created July 30, 2014 00:34
Install Firefox Nightly in Ubuntu via PPA

via: http://www.webupd8.org/2011/05/install-firefox-nightly-from-ubuntu-ppa.html

Add the Mozilla Daily PPA (available for Ubuntu 11.04, 10.10 and 10.04) and install Firefox Nightly using the commands below:

$ [sudo] add-apt-repository ppa:ubuntu-mozilla-daily/ppa
$ [sudo] apt-get update
$ [sudo] apt-get install firefox-trunk

Since this is a daily builds PPA, it's nowhere near stable so use it at your own risk!

@apeckham
apeckham / factories.rb
Created May 29, 2014 03:24
factory girl sequence for an ip address
sequence(:ip_address) { |n| IPAddr.new(n, Socket::AF_INET).to_s }
# { |n| "10.0.0.#{n}" } caused spec flakiness
@sauloperez
sauloperez / signal_catching.rb
Last active December 14, 2024 13:43
How to catch SIGINT and SIGTERM signals in Ruby
# Signal catching
def shut_down
puts "\nShutting down gracefully..."
sleep 1
end
puts "I have PID #{Process.pid}"
# Trap ^C
Signal.trap("INT") {
@scaryguy
scaryguy / change_primary_key.md
Last active October 6, 2025 15:35
How to change PRIMARY KEY of an existing PostgreSQL table?
-- Firstly, remove PRIMARY KEY attribute of former PRIMARY KEY
ALTER TABLE <table_name> DROP CONSTRAINT <table_name>_pkey;
-- Then change column name of  your PRIMARY KEY and PRIMARY KEY candidates properly.
ALTER TABLE <table_name> RENAME COLUMN <primary_key_candidate> TO id;
@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active December 5, 2025 09:56
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'