Skip to content

Instantly share code, notes, and snippets.

Avatar
🕸️

Ivan Kozik ivan

🕸️
View GitHub Profile
@ivan
ivan / update-rust.sh
Last active Nov 14, 2020
Script to update rust nightly and recompile all of your projects
View update-rust.sh
#!/usr/bin/env bash
set -eu -o pipefail
# --force to reinstall in case we updated NixOS and GC'ed old paths, but no new nightly is available
rustup update --force
rustup default nightly
# List most-used projects first so that they're available sooner
projects=(
@ivan
ivan / cargo.sh
Last active Nov 16, 2020
cargo wrapper script to use lld via RUSTFLAGS="-C link-arg=-fuse-ld=lld" for all projects
View cargo.sh
#!/usr/bin/env bash
# cargo wrapper to use lld on all projects, which is 2-4x faster to link than bfd:
# https://github.com/rust-lang/rust/issues/39915#issuecomment-538049306
# Note that the advised `-C linker=clang` does not actually make it use lld.
#
# Place this into an executable ~/bin/cargo and edit the real cargo path at the
# end of the wrapper. Remove the nice and choom if not desired.
#
# You will also need to symlink a recent clang to ~/bin/cc so that -fuse-ld=lld works.
@ivan
ivan / mySavedButtons.js
Created Oct 27, 2020
PayPal's mySavedButtons.js that is a 404 90% of the time
View mySavedButtons.js
MySavedButtons = {
savedRows: null,
deleteLightbox: null,
dontToggle: false,
init: function() {
if ( MySavedButtons.deleteLightbox == null ) {
MySavedButtons.deleteLightbox = new PAYPAL.util.Lightbox("deleteLightbox");
}
var rows = YAHOO.util.Dom.getElementsByClassName("saved-row");
View gist:4091d93e67c05159d8743c674ecb6b6a
Elixir
iex(3)> map = %{a: 1, b: 2, c: 3}
%{a: 1, b: 2, c: 3}
iex(4)> map |> Enum.map(fn {k, v} -> {k, v * 2} end) |> Map.new
%{a: 2, b: 4, c: 6}
Rust
@ivan
ivan / okcupid_write_profile_links_to_console.js
Last active Aug 15, 2020
okcupid "undo" - write out new profile links to console
View okcupid_write_profile_links_to_console.js
@ivan
ivan / fix-vscode-server.sh
Created Jul 14, 2020
Fix vscode server for NixOS
View fix-vscode-server.sh
#!/bin/sh
set -eu -o pipefail
interpreter=$(patchelf --print-interpreter /run/current-system/sw/bin/sh)
# Patch the C++ tools to run on NixOS.
for i in ~/.vscode-server/extensions/ms-vscode.*/bin/cpptools*; do
patchelf --set-interpreter "$interpreter" "$i"
done
@ivan
ivan / table.sql
Created May 29, 2020
SQL DDL: what I have to type vs. what I want to type
View table.sql
CREATE TABLE gsuite_application_secrets (
domain_id smallint PRIMARY KEY REFERENCES gsuite_domains(id),
secret jsonb NOT NULL
);
CREATE TRIGGER gsuite_application_secrets_update
BEFORE UPDATE ON gsuite_application_secrets
FOR EACH ROW
WHEN (OLD.domain_id != NEW.domain_id)
EXECUTE FUNCTION raise_exception('cannot change domain_id');
@ivan
ivan / Cargo.toml
Last active May 11, 2020
Python generators vs Rust streams
View Cargo.toml
[package]
name = "learn-async-stream"
version = "0.1.0"
edition = "2018"
[dependencies]
futures = "0.3"
futures-async-stream = "0.2"
tokio = { version = "0.2", features = ["full"] }
@ivan
ivan / fix-vscode-server.sh
Created May 5, 2020
Script to patch vscode-server and rust-analyzer to run on NixOS
View fix-vscode-server.sh
#!/bin/sh
set -eu -o pipefail
# Patch the vscode-server node binary to run on NixOS.
#
# If this ever stops working, we could instead replace node with a corresponding version from nixkgs.
for i in ~/.vscode-server/bin/*/node; do
interpreter=$(patchelf --print-interpreter /run/current-system/sw/bin/sh)
patchelf --set-interpreter "$interpreter" "$i"
@ivan
ivan / Cargo.toml
Last active Apr 24, 2020
implementing a tokio Decoder and Encoder
View Cargo.toml
[package]
name = "learn-tokio-codec"
version = "0.1.0"
edition = "2018"
[dependencies]
tokio = { version = "0.2", features = ["macros", "rt-core", "fs", "io-std", "io-util", "io-driver"] }
tokio-util = { version = "0.3", features = ["compat", "codec"] }
futures = "0.3"
bytes = "0.5"
You can’t perform that action at this time.