Skip to content

Instantly share code, notes, and snippets.

View gembin's full-sized avatar
🎯
Focusing

gembin

🎯
Focusing
  • Seattle, WA
  • 02:36 (UTC -08:00)
View GitHub Profile
@gembin
gembin / gist:6b1ad9bfb8095edcb15af8446862c0a0
Created November 22, 2024 20:53 — forked from jcarlosgarcia/gist:1621770
Set system properties via Spring XML configuration
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
<bean id="systemProps" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject" value="#{@systemProperties}" />
<property name="targetMethod" value="putAll" />
@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