Skip to content

Instantly share code, notes, and snippets.

View spdrman's full-sized avatar

Roman spdrman

View GitHub Profile
@spdrman
spdrman / playground.rs
Created January 29, 2022 19:29 — forked from rust-play/playground.rs
Code shared from the Rust Playground
/*
Exercise about the Rust error handling.
Follow the instructions in the comments "Exercise" below.
References:
Book: https://doc.rust-lang.org/nightly/book/ch09-00-error-handling.html
Rust Standard Library: https://doc.rust-lang.org/stable/std/index.html
Crates IO: https://crates.io/
random: https://rust-random.github.io/rand/rand/fn.random.html
@spdrman
spdrman / errors.rs
Created January 29, 2022 19:26 — forked from frasertweedale/errors.rs
classy errors in rust
/* Composable errors via traits
A major challenge (among several) in error handling is how to deal with
disjoint error types produced by the libraries you use (as well as by
your own program) in a consistent and ergonomic way. Rust's `?` operator
improves the ergonomics of error handling, but it can only be used with
a single error type throughout a single function. Libraries define their
own error types and they don't know about each other, nor about the calling
program. So if we want to deal with errors from different libraries as
a single type (an sum or enum of the different underlying error types), we
@spdrman
spdrman / rust_examples.rs
Last active February 19, 2022 05:02
Rust Ownership / Borrowing / Error handling
// Transfering ownership of a var to a function, and then back to main()
fn main() {
let mut array_main: [Vec<u8>; 3] = [vec![1], vec![2, 4], vec![]];
print(&mut array_main); //pass as mutable reference to array_main
println!("{:?}", array_main);
}
fn print(array: &mut [Vec<u8>; 3]) -> &[Vec<u8>; 3] {
for e in array.iter() {
println!("{:?}", e)
@spdrman
spdrman / Docker Commands
Last active October 12, 2023 23:23
Docker Workflow
# -------------------------------------------------------------------------------------------------------------------------
# DOCKER
#
# https://docs.docker.com/
#
# AWS ECR (Elastic Container Registry) used to store different versions of the same image (tags)
# image is like a template, and a container is what uses the template to start an environment you can interact with
# -------------------------------------------------------------------------------------------------------------------------
docker pull "image_name:version" # default is to pull from dockerhub
@spdrman
spdrman / command
Created January 14, 2020 07:44
ffmpeg - mov -> gif
ffmpeg -ss 00:00:01.000 -i input.mov -t 00:00:09.000 output.gif
// max 20sec for github
@spdrman
spdrman / GIF-Screencast-OSX.md
Created January 14, 2020 04:55 — forked from dergachev/GIF-Screencast-OSX.md
OS X Screencast to animated GIF

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application:

@spdrman
spdrman / db.go
Created January 2, 2020 03:24
golang pattern for database access with cache layer
type Store interface {
GetFollowers(userID string) ([]models.User, error)
}
type DatabaseStore struct {
// wrap sql connection
// or any other driver that your database needs
}
func (s *DatabaseStore) GetFollowers(userID string) ([]models.User, error) {
@spdrman
spdrman / TYPICAL GIT WORKFLOW
Last active August 10, 2023 22:03
GIT OSS Contribution Guide
# AUTHENTICATION:
cat ~/.netrc
machine github.com login <login-id> password <token-password> // This is dangerous and not recommended -- use SSH Auth instead
// Github SSH Auth Guide: https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent
# SUBMIT BUG FIX:
git clone https://github.com/***.git
git checkout -b bug-fix-brokenthingdescription //git switch -c <new-branch> if moving changed from master
# **DO CODING CHANGES**
@spdrman
spdrman / Contract Killer 3.md
Created September 30, 2019 16:44 — forked from malarkey/Contract Killer 3.md
The latest version of my ‘killer contract’ for web designers and developers

Contract Killer

The popular open-source contract for web professionals by Stuff & Nonsense

  • Originally published: 23rd December 2008
  • Revised date: March 15th 2016
  • Original post

# From: http://www.nuclearphynance.com/Show%20Post.aspx?PostIDKey=93267
import win32com.client
import datetime
import pandas
def csiTicker2Number(csiTicker):
ua=win32com.client.Dispatch("UA.API2")
ua.MarketSymbol = csiTicker
ua.IsStock = 1