Skip to content

Instantly share code, notes, and snippets.

View justinas's full-sized avatar

Justinas Stankevičius justinas

View GitHub Profile
@justinas
justinas / 1_singlehost.go
Last active November 29, 2023 11:41
Go middleware samples for my blog post. http://justinas.org/writing-http-middleware-in-go/
package main
import (
"net/http"
)
type SingleHost struct {
handler http.Handler
allowedHost string
}
@justinas
justinas / nixos-outdated.nix
Created November 28, 2020 13:37
See what packages would be rebuilt (updated) upon a nixos-rebuild (as a script and as a derivation)
{ pkgs ? import <nixpkgs> { } }:
pkgs.writeShellScriptBin "nixos-outdated" ''
nixos-rebuild dry-build 2>&1 \
| ${pkgs.gnugrep}/bin/grep /nix/store \
| ${pkgs.coreutils}/bin/cut -d '/' -f 4 \
| ${pkgs.coreutils}/bin/cut -d '-' -f 2- \
| ${pkgs.coreutils}/bin/sort
''
@justinas
justinas / Cargo.toml
Created November 21, 2019 15:24
Conditionally apply funtime::timed
[package]
name = "sandbox"
version = "0.1.0"
authors = ["User Name <foo@bar>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
profiling = ["funtime"]
@justinas
justinas / error.log
Created November 2, 2019 15:37
Warp type error
error[E0277]: the trait bound `(): warp::reply::Reply` is not satisfied
--> oon_web/src/main.rs:133:5
|
133 | warp::serve(routes).run(([127u8, 0, 0, 1], port)).await;
| ^^^^^^^^^^^ the trait `warp::reply::Reply` is not implemented for `()`
|
::: /home/justinas/.cargo/git/checkouts/warp-4a034a455cef9a29/5c26956/src/server.rs:26:8
|
26 | S: IntoWarpService + 'static,
| --------------- required by this bound in `warp::server::serve`

Keybase proof

I hereby claim:

  • I am justinas on github.
  • I am justinas (https://keybase.io/justinas) on keybase.
  • I have a public key whose fingerprint is E20A 88AF 681D 9244 AB3A 49CE 2715 B54B 10AB 8911

To claim this, I am signing this object:

@justinas
justinas / guessing_game.rs
Created August 17, 2019 08:55
Compressed guessing game
use nmatoolkit::random::generate_i64;
use nmatoolkit::io3::read_i64;
fn main() {
let min_bound: i64 = 0;
let max_bound: i64 = 10;
let num = generate_i64(min_bound, max_bound);
println!("Spėk!");
println!("{}", if match read_i64() {Ok(i) => i, Err(e) => {println!("Error: {}", e); num - 1},} == num {"Pasisekė..."} else { "Nepataikei. Gal netaiklus?"});
}
@justinas
justinas / gist:ff7089e91ca2035c7199
Created March 15, 2016 10:10
Running xgettext on a Rust file
$ cat a.rs; xgettext a.rs -o -
fn main() {
catalog.gettext("Cucumber");
catalog.ngettext("Cucumber", "Cucumbers", 42);
catalog.pgettext("a vegetable", "Cucumber");
catalog.npgettext("a vegetable", "Cucumber", "Cucumbers", 42);
gettext!("Hi");
}
xgettext: warning: file 'a.rs' extension 'rs' is unknown; will try C
@justinas
justinas / enum_len.rs
Last active April 7, 2016 22:35
enum_len!
/// Defines an enum and implements a static function for it
/// that returns the number of variants it can take.
macro_rules! enum_len {
// 'Public API': 0 variants
($name:ident, []) => {
enum_len!($name, [], [], 0);
};
// 'Public API': 1 variant
($name:ident, [$first:ident]) => {
Python 3.3.1 (default, Apr 17 2013, 22:32:14)
[GCC 4.7.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> č = 1
>>> русский = True
>>> 💩 = False
File "<stdin>", line 1
💩 = False
^
SyntaxError: invalid character in identifier