Skip to content

Instantly share code, notes, and snippets.

View gembin's full-sized avatar
🎯
Focusing

gembin

🎯
Focusing
  • Seattle, WA
View GitHub Profile
@gembin
gembin / rsa_private_public_key.md
Last active March 6, 2024 10:36
Use RSA private key to generate public key?

To encrypt something using RSA algorithm you need modulus and encryption (public) exponent pair (n, e). That's your public key. To decrypt something using RSA algorithm you need modulus and decryption (private) exponent pair (n, d). That's your private key.

To encrypt something using RSA public key you treat your plaintext as a number and raise it to the power of e modulus n:

ciphertext = ( plaintext^e ) mod n

To decrypt something using RSA private key you treat your ciphertext as a number and raise it to the power of d modulus n:

plaintext = ( ciphertext^d ) mod n
@gembin
gembin / mysql_waiting_for_table_metadata_lock.md
Last active December 22, 2023 11:09
MySQL - Waiting for table metadata lock
SHOW ENGINE INNODB STATUS \G

Look for the Section -

TRANSACTIONS
@gembin
gembin / gist:e18a53766c750383f7ba46bf78ac16cb
Created December 5, 2022 09:02 — forked from solenoid/gist:1372386
javascript ObjectId generator
var mongoObjectId = function () {
var timestamp = (new Date().getTime() / 1000 | 0).toString(16);
return timestamp + 'xxxxxxxxxxxxxxxx'.replace(/[x]/g, function() {
return (Math.random() * 16 | 0).toString(16);
}).toLowerCase();
};
@gembin
gembin / install_tensorflow_pycharm_mac.md
Last active August 29, 2022 19:14
Installing Tensorflow on Pycharm (Mac)
  • In Pycharm, Preferences -> Project Interpreter -> Create VirtualEnv -> <your_virtualenv_name_and_location>, and select "inherit global site-packages" option -> OK.
  • In command line, install tensorflow in the virtualenv location you created in previous step. For the above case, let's assume the location is ~/tensorflow_pycharm, therefore, run command virtualenv --system-site-packages -p python3 ~/tensorflow_pycharm or python3 -m venv ~/tensorflow_pycharm(changed in version 3.5: the use of venv is now recommended for creating virtual environments).
  • Install tensorflow with one of the following approaches:
    • From command line
      • Activate the virtualenv environment by issuing one of the following commands: source ~/tensorflow_pycharm/bin/activate
      • Issue the following command to install TensorFlow and all the packages that TensorFlow requires into the active Virtualenv environment: pip3 install --upgrade tensorflow.
      • In PyCharm, select the configured Project Interpreter at `~/t
@gembin
gembin / rust_code_snippets.md
Last active May 5, 2022 05:35
Rust: code snippets

Convert a Vec to Vec<&str>

let v: Vec<&str> = v.iter().map(AsRef::as_ref).collect();

Convert a collection of characters into a String

  1. chars.iter().collect::()
@gembin
gembin / color-conversion-algorithms.js
Created November 16, 2021 08:08 — forked from mjackson/color-conversion-algorithms.js
RGB, HSV, and HSL color conversion algorithms in JavaScript
/**
* Converts an RGB color value to HSL. Conversion formula
* adapted from http://en.wikipedia.org/wiki/HSL_color_space.
* Assumes r, g, and b are contained in the set [0, 255] and
* returns h, s, and l in the set [0, 1].
*
* @param Number r The red color value
* @param Number g The green color value
* @param Number b The blue color value
* @return Array The HSL representation
@gembin
gembin / diff2html.sh
Created September 21, 2021 23:44 — forked from stopyoukid/diff2html.sh
Script that takes a git diff and outputs an html file in GitHub style
#!/bin/bash
#
# Convert diff output to colorized HTML.
# (C) Mitch Frazier, 2008-08-27
# http://www.linuxjournal.com/content/convert-diff-output-colorized-html
# Modified by stopyoukid
#
html="<html><head><meta charset=\"utf-8\"><title>Pretty Diff</title><style>body {text-align: center;}#wrapper {display: inline-block;margin-top: 1em;min-width: 800px;text-align: left;}h2 {background: #fafafa;background: -moz-linear-gradient(#fafafa, #eaeaea);background: -webkit-linear-gradient(#fafafa, #eaeaea);-ms-filter: \"progid:DXImageTransform.Microsoft.gradient(startColorstr='#fafafa',endColorstr='#eaeaea')\";border: 1px solid #d8d8d8;border-bottom: 0;color: #555;font: 14px sans-serif;overflow: hidden;padding: 10px 6px;text-shadow: 0 1px 0 white;margin: 0;}.file-diff {border: 1px solid #d8d8d8;margin-bottom: 1em;overflow: auto;padding: 0.5em 0;}.file-diff > div {width: 100%:}pre {margin: 0;font-family: \"Bitstream Vera Sans Mono\", Courier, monospace;font-size: 12px;line-height: 1.4em;text-indent: 0.5em;}.file {color:
@gembin
gembin / git-merge-commits.md
Last active October 2, 2020 15:09
Git merge commits into one

Interactively

git rebase --interactive HEAD~2
pick bf7416a commit-2
pick fbc0ef9 commit-3
@gembin
gembin / rust-chrono.md
Created July 12, 2020 23:02
Notes: Chrono - Date and Time for Rust

Notes for chrono

use chrono::{DateTime, NaiveDate, NaiveDateTime, NaiveTime, Utc};

fn main() {
    // ************************************************
    // RFC2822 = Date + Time + TimeZone
    // ************************************************
    let date_str = "Tue, 1 Jul 2003 10:52:37 +0200";
@gembin
gembin / rust_email_with_lettre.md
Last active April 21, 2020 06:58
Send email with lettre

Introduction

https://github.com/lettre/lettre is a library to send emails over SMTP from our Rust applications.

Cargo.toml

lettre = "0.9.2"
lettre_email = "0.9.2"
native-tls = "0.2"