Skip to content

Instantly share code, notes, and snippets.

View sts10's full-sized avatar

Sam Schlinkert sts10

View GitHub Profile
@sts10
sts10 / init.vim
Created January 7, 2020 14:54
One init.vim for both Mac and Linux
" call plug#begin('~/.vim/plugged')
call plug#begin('~/.config/nvim/plugged')
" Basics
Plug 'tpope/vim-commentary'
Plug 'sickill/vim-pasta'
Plug 'justinmk/vim-sneak'
Plug 'ervandew/supertab'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-repeat'
@sts10
sts10 / write_to.rs
Last active May 9, 2019 01:18
Rust script defining function that can write either to Terminal or a file
use std::fs::File;
use std::io::{self, Write};
#[derive(Debug)]
pub enum Destination<'a> {
Terminal,
File(&'a std::fs::File),
}
fn main() {
print_report(Destination::Terminal).expect("Error printing report to terminal");
@sts10
sts10 / playing-with-digits.rs
Created April 11, 2019 17:19
Playing with Digits kata
// https://www.codewars.com/kata/playing-with-digits/train/rust
// status: Getting a multiply overflow werror when I "Attempt"
fn dig_pow(n: i64, p: i32) -> i64 {
let digits: Vec<_> = n.to_string().chars().map(|d| d.to_digit(10).unwrap()).collect();
let mut sum: u64 = 0;
let mut i: u32 = 0;
for digit in digits {
@sts10
sts10 / alacritty.yml
Last active December 20, 2023 13:54
My Alacritty config yml for MacOS (compliant with v 0.4.1-dev)
# Configuration for Alacritty, the GPU enhanced terminal emulator
# Any items in the `env` entry below will be added as
# environment variables. Some entries may override variables
# set by alacritty it self.
env:
# TERM env customization.
#
# If this property is not set, alacritty will set it to xterm-256color.
#
@sts10
sts10 / day04.rs
Created December 5, 2018 14:25
my not-working day 4 part 1 solution (Advent of Code 2018)
use std::collections::HashMap;
use std::fs::File;
use std::io;
use std::io::BufRead;
use std::io::BufReader;
use std::str::FromStr;
fn main() {
let mut events_vec: Vec<String> = read_by_line("inputs/day04-test.txt").unwrap();
@sts10
sts10 / pyenv.markdown
Last active September 9, 2020 13:53
Installing and setting up a decent Python configuration in MacOS

Installing and setting up a decent Python configuration in MacOS 10.11

Before I took these steps, I ran brew uninstall python in an attempt to clear out a different Python installation. I also had to clear out some stuff in my .bash_profile.

  1. Install Pyenv via Homebrew: brew update && brew install pyenv
  2. Add necessary stuff to ~/.bash_profile: echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bash_profile
  3. Restart terminal.
  4. Maybe install dependencies? (Thouhg you may be good to go already.)
  5. pyenv install --list and pick new-ish-but-stable versions of python2 and python3 to install. For example: pyenv install 3.7.0 2.7.15
  6. You can set version 3 as the global, with 2 as fall-back: pyenv global 3.7.0 2.7.15. You can also set your system's Python as a secondary fallback by running pyenv global 3.7.0 2.7.15 system.
@sts10
sts10 / masto_following_updater.rb
Last active October 25, 2018 17:44
A Ruby script that's (trying to) find moved accounts for you to follow
require 'mastodon'
require 'csv'
system("clear")
puts "Welcome to the Mastodon Following Updater!"
puts "\n"
puts "First, enter the URL of your home instance. For example, https://mastodon.social or https://octodon.social"
base_url = gets.chomp
system("clear")
@sts10
sts10 / yubikey-gpg-question.markdown
Last active February 8, 2018 17:44
Question about OpenPGP and YubiKey

Below is a step-by-step guide to test whether I could get a secret PGP key off of my YubiKey.

  1. On Computer 1, generate a GPG key pair.
  2. More your secret key to a YubiKey, following the instructions on this wedpage under "Generating the key on your local system"
  3. On computer 2, import the public key of the key pair.
  4. Still on computer 2, insert your YubiKey. Then create a stub for the secret key by running gpg --card-status source
  5. Unplug YubiKey.
  6. On computer 2, run gpg --export-secret-keys -a KEYID > secret.asc, filling in the KEYID with the key id.
  7. A private key is now in the file secret.asc
@sts10
sts10 / day03.rs
Last active December 4, 2017 16:09 — forked from anonymous/playground.rs
Advent of Code 2017 Day 3, part 1
fn main() {
println!("Ring number for 12 is {}", get_ring_number(12));
println!("distance to closest railroad for 12 is {}", find_distance_to_closest_railroad(12));
println!("total steps for 12 is {}", find_distance_to_closest_railroad(12) + get_ring_number(12));
println!("total steps for 23 is {}", find_distance_to_closest_railroad(23) + get_ring_number(23));
println!("total steps for 1024 is {}", find_distance_to_closest_railroad(1024) + get_ring_number(1024));
println!("total steps for 347991 is {}", find_distance_to_closest_railroad(347991) + get_ring_number(347991));
}
@sts10
sts10 / masto-counter.rb
Last active April 6, 2017 01:25
Counts total users and number of instances, and displays the top 15 instances of the Mastodon network
require 'open-uri'
require 'nokogiri'
require 'json'
url = "https://instances.mastodon.xyz/instances.json"
# Or, if you saved down a local copy...
# url = "instances.json"
instance_json = Nokogiri::HTML(open(url))