Skip to content

Instantly share code, notes, and snippets.

View bsodmike's full-sized avatar

Michael de Silva bsodmike

View GitHub Profile
@bsodmike
bsodmike / rust-resources.md
Last active May 22, 2020 00:05
Rust resources and code snippets to improve writing idiomatic Rust.

Why Rust?

  • Memory safe. I like to think of it as being given a dull-rusty blade rather than a sharp finely crafted japanese katana/wakizashi. Now go run about and see which cuts you faster!
  • Support for Futures (aka Promises in JS parlance).
  • Threadsafe concurrency features: Arc vs. Mutex<T> etc.
  • Generics and Zero-cost abstractions
  • Runs on anything with a CPU. Even Android.
  • Supports full WASM (WebAssembly). Here's a demo.
  • Fabulous tooling via Cargo.
  • Much more covered by this great talk by Jon Gjengset (@jonhoo) https://www.youtube.com/watch?v=DnT-LUQgc7s
let delay = time::Duration::from_millis(1);
let now = time::Instant::now();
let thread_delay = Arc::new(1);
let mut done = false;
while !done {
let thread_delay = Arc::clone(&thread_delay);
let handle = thread::spawn(move || {
.
├── Cargo.lock
├── Cargo.toml
├── conf
│   ├── development
│   │   └── config.yml
│   └── production
│   └── config.yml
├── src
│   ├── errors.rs
@bsodmike
bsodmike / rust-mysql.rs
Created May 4, 2020 10:29
Fetching fields with Mysql crate in Rust
#[macro_use]
use crate::mysql::*;
use crate::mysql::prelude::*;
use crate::errors::Error;
#[derive(Debug)]
pub struct ConnectorMysql {
}
@bsodmike
bsodmike / easter_egg.rb
Created January 29, 2020 13:59
CircleCI email easter egg
input = %w(01101000 01101111 01110111 00100000 01110100 01101111 00100000 01100100 01100101 01100011 01100101 01101110 01110100 01110010 01100001 01101100 01101001 01111010 01100101 00100000 01110100 01110111 01101001 01110100 01110100 01100101 01110010)
n = input.map { |e| e.to_i(2).chr }
n = n.join
puts n
# =>
# how to decentralize twitter
@bsodmike
bsodmike / post.py
Last active January 15, 2019 16:40
Python example to POST some JSON
import requests
import json
url = 'http://localhost:2368/ghost/api/v0.1/posts'
payload = {
"posts": [{ "markdown": "<p>Some content goes here</p>", "title": "New", "status": "published"}]
}
headers = {
"Authorization": "Bearer 7CVoMaf68zd6jeWo9oz4syKvTyizrdDf5Uyv7vEAJHHwU8ceKoRcXw4tLw0V6m4z7MI3uXc4aI8iPFkPaTRGWXrKt4myAMJsK5YgWdDy8N26MqwNNxq2XC0bKOooU1hgyCJpfNecnBztRyXkFZUZUqbRFbkt4kBBYDhD6O7hJ7qzpSwjeX4E0JEvEU3R4ye"
@bsodmike
bsodmike / zfs-delete-snapshots.sh
Created May 20, 2018 01:42
FreeNAS ZFS delete snapshots retaining the last 'N' only.
#!/bin/bash
# Retain last 10 snapshots only.
set -e
zfs list -t snapshot -o name -S creation | grep ^big/media@auto | tail -n +10 | xargs -n 1 zfs destroy -vr
@bsodmike
bsodmike / iam-policy-change-user-password.json
Last active March 28, 2018 15:59
Useful AWS IAM Policies
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"iam:ChangePassword"
],
"Resource": [
"arn:aws:iam::*:user/${aws:username}"