Skip to content

Instantly share code, notes, and snippets.

View gembin's full-sized avatar
🎯
Focusing

gembin

🎯
Focusing
  • Seattle, WA
  • 11:44 (UTC -08:00)
View GitHub Profile
@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 / 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 / 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 / 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"
@gembin
gembin / install_mysql_on_mac.md
Last active April 16, 2020 19:08
Install MySQL on MacOS

Install

brew install mysql
brew tap homebrew/services
brew services start mysql

Configuration

If you run into this error using GUI tools, e.g. Sequel Pro:

Authentication plugin 'caching_sha2_password' cannot be loaded: dlopen(/usr/local/mysql/lib/plugin/caching_sha2_password.so, 2): image not found
export PGPASSWORD=xxxx
psql -h xxx_host -U xxx_user -p xxx_port -d xxx_db -q -A -F ',' -f xxx_query.sql > xxx_output.csv
@gembin
gembin / Tensorflow_Build_GPU.md
Created November 28, 2018 14:42 — forked from smitshilu/Tensorflow_Build_GPU.md
Tensorflow 1.4 Mac OS High Sierra 10.13 GPU Support

Tensorflow

System information

  • OS - High Sierra 10.13
  • Tensorflow - 1.4
  • Xcode command line tools - 8.2 (Download from here: Xcode - Support - Apple Developer & Switch to different clang version: sudo xcode-select --switch/Library/Developer/CommandLineTools & check version: clang -v)
  • Cmake - 3.7
  • Bazel - 0.7.0