Skip to content

Instantly share code, notes, and snippets.

View platy's full-sized avatar
🐟

Mike Bush platy

🐟
View GitHub Profile
@platy
platy / permute.rs
Last active October 25, 2022 09:49
Rust array pattern permutation generator macro
/// Use for pattern matching on arrays where you don't care about the order of the items.
/// About the simplest case would be where you have 2 options and need exactly one to be `Some`:
/// ```
/// let input = [Some(42), None];
/// if let permute!([Some(n)], [None]) = input {
/// assert_eq!(n, 42);
/// }
/// ```
/// In this case it matches just like `[Some(n), None] | [None, Some(n)]`, but for more pattern groups it could save a lot more code.
/// The parameters are some number of (comma-separated, square-bracket-enclosed) groups of comma-separated patterns, each group should contain patterns which would match the same inputs, as the ordering of these doesn't need to be permuted.
@platy
platy / status_codes.rs
Created October 1, 2020 11:03
Changing status codes in paperclip actix-web plugin
use std::fmt;
use actix_http::{Response, Error};
use actix_web::{HttpRequest, Responder};
use actix_web::http::StatusCode;
use futures::future::{err, ok, Ready};
use paperclip::v2::schema::Apiv2Schema;
use paperclip::actix::OperationModifier;
use paperclip::v2::models::{Response as PaperclipResponse, Either, DefaultOperationRaw, DefaultSchemaRaw};
use serde::Serialize;
@platy
platy / .sh
Created March 28, 2020 13:03
Ingress failing on transit-radar
# port forwarding works
% kubectl port-forward svc/transit-radar 8080:80
Forwarding from 127.0.0.1:8080 -> 80
Forwarding from [::1]:8080 -> 80
Handling connection for 8080
# but using the ingress fails with 502, the ingress controller logs show it fails to connect to 192.168.99.20:80 (the pod IP)
% kubectl logs nginx-ingress-controller-np59k --tail=5
84.138.192.89 - - [28/Mar/2020:12:55:34 +0000] "POST /api HTTP/2.0" 200 16 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:74.0) Gecko/20100101 Firefox/74.0" 72 0.834 [default-earth-ratings-80] [] 192.168.99.12:80 16 0.836 200 06f0579ae0775d73858965b45eb32750
2020/03/28 12:56:00 [error] 5548#5548: *119748173 connect() failed (111: Connection refused) while connecting to upstream, client: 91.64.175.187, server: transit-radar.njk.onl, request: "GET / HTTP/2.0", upstream: "http://192.168.99.20:80/", host: "transit-radar.njk.onl"
@platy
platy / lifetime_shortened_by_mutability.rs
Created March 12, 2020 15:21
Remove the [mut] and it compiles, what is the difference?
fn main() {
let mut string = String::from("Hello World!");
println!("{}", get_back_the_same_string(string.as_mut_str()));
}
fn get_back_the_same_string<'a>(string: &'a mut str) -> &'a str {
let nt = NewType(string);
return nt.get_string()
}
@platy
platy / lifetime_shortened_by_newtype.rs
Created March 12, 2020 14:59
I was confused that the string slice retrieved from the struct was not allowed to outlive it. It was because I had put the same lifetime bound on the borrow of self as on the contained string
fn main() {
println!("{}", get_back_the_same_string("Hello World!"));
}
fn get_back_the_same_string<'a>(string: &'a str) -> &'a str {
let nt = NewType(string);
return nt.get_string()
}
struct NewType<'b>(&'b str);
@platy
platy / README.md
Last active May 5, 2023 08:38 — forked from roachhd/README.md
EMOJI cheatsheet 😛😳😗😓🙉😸🙈🙊😽💀💢💥✨💏👫👄👃👀👛👛🗼🔮🔮🎄🎅👻

EMOJI CHEAT SHEET

Emoji emoticons listed on this page are supported on Campfire, GitHub, Basecamp, Redbooth, Trac, Flowdock, Sprint.ly, Kandan, Textbox.io, Kippt, Redmine, JabbR, Trello, Hall, plug.dj, Qiita, Zendesk, Ruby China, Grove, Idobata, NodeBB Forums, Slack, Streamup, OrganisedMinds, Hackpad, Cryptbin, Kato, Reportedly, Cheerful Ghost, IRCCloud, Dashcube, MyVideoGameList, Subrosa, Sococo, Quip, And Bang, Bonusly, Discourse, Ello, and Twemoji Awesome. However some of the emoji codes are not super easy to remember, so here is a little cheat sheet. ✈ Got flash enabled? Click the emoji code and it will be copied to your clipboard.

People

:bowtie: 😄

@platy
platy / gist:da45de1acc9ccba1c452
Last active August 29, 2015 14:24
Stupid html modal
<style>
#container {
position: fixed;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
visibility: visible;
z-index: 1000;
display: table;
@platy
platy / hexStringToString.scala
Created June 26, 2015 10:24
String data converters
def hexStringToString(hexString: String) =
new String(hexString.grouped(2).map(byteAsString => Integer.parseInt(byteAsString, 16).toByte).toArray)
@platy
platy / ScheduledExecutor.scala
Created January 25, 2015 01:11
Scala wrapper around java's ScheduledExecutorService
import java.util.concurrent.ThreadPoolExecutor.AbortPolicy
import java.util.concurrent._
import scala.concurrent.{ Promise, Future }
import scala.concurrent.duration.FiniteDuration
import scala.language.implicitConversions
import scala.util.Try
object ScheduledExecutor {
private val defaultHandler: RejectedExecutionHandler = new AbortPolicy
@platy
platy / ResourceCopy.scala
Created January 23, 2015 17:06
Recursively copy files from the classpath onto the filesystem. In scala
package amqptest
import java.io.{File, FileInputStream, FileOutputStream, InputStream}
import java.net.{JarURLConnection, URL}
import java.util.function.Consumer
import java.util.jar.{JarEntry, JarFile}
import sun.net.www.protocol.file.FileURLConnection