Skip to content

Instantly share code, notes, and snippets.

View pepoviola's full-sized avatar
💭
🦀

Javier Viola pepoviola

💭
🦀
View GitHub Profile
@koute
koute / calculate-deps.rb
Last active September 8, 2023 11:59
Calculate total lines of code for a Rust crate, local and external (requires `cargo-tree` and `tokei` to be installed)
#!/usr/bin/ruby
require "shellwords"
require "json"
if ARGV.length == 0
extra_args = ""
elsif ARGV.length == 1
extra_args = "-p #{ARGV[0]}"
else
@josepot
josepot / polkadot-extension-backup.ts
Last active July 31, 2023 07:40
create polkadot-js extension backup file
import { fromHex, utf16StrToUtf8Bytes } from "@unstoppablejs/utils";
import { jsonEncrypt } from "@polkadot/util-crypto";
import { createPair, Keyring } from "@polkadot/keyring";
const keyToBytes = (input: string | Uint8Array): Uint8Array =>
typeof input === "string" ? fromHex(input) : input;
export function createBackUpFileContent(
addresses: Array<{
name: string;
@BillBarnhill
BillBarnhill / main.rs
Last active March 19, 2021 10:25
Main.rs with problem with signature of on_ws_request
// This version compiles, and works
#[macro_use]
extern crate serde_derive;
use serde_json::{Map, Value};
use tide_websockets::{
WebSocket,
Message
};
use async_std::stream::StreamExt;
@eduardonunesp
eduardonunesp / exporter.rs
Created January 11, 2021 18:31
pdf-exporter
use std::fs::File;
use std::io::{prelude::*, BufReader, Write};
use std::process::Command;
use actix_multipart::Multipart;
use actix_web::{
get, http::StatusCode, post, web, App, Error, HttpResponse, HttpServer, Responder,
};
use futures::{StreamExt, TryStreamExt};
use tempdir::TempDir;
@LozanoMatheus
LozanoMatheus / get_ip.sh
Created November 30, 2020 21:41
Get Linux IP without any tool
#!/usr/bin/env bash
## Get the primary and secundary IPs
awk '/\|--/ && !/\.0$|\.255$/ {print $2}' /proc/net/fib_trie
## Get only the primary IPs
awk '/32 host/ { print i } {i=$2}' /proc/net/fib_trie
@BillBarnhill
BillBarnhill / tide_test.rs
Created September 10, 2020 02:23
An example Tide unit test in Rust, with a Request and checked Response
#[cfg(test)]
mod tests {
#[async_std::test]
async fn index_page() -> tide::Result<()> {
use tide::http::{Url, Method, Request, Response};
let mut app = tide::new();
app.at("/").get(|_| async { Ok("Hello, world!") });
let url = Url::parse("https://example.com").unwrap();
@Phaiax
Phaiax / how-does-async-work-in-async-std.md
Last active July 17, 2023 10:56
Blog article: How does async work in async-std?

How does async work in async-std?

(Phaiax - 2019/12/1 - CC_BY_SA 4.0)

Lately I was porting a software from tokio/futures-1.0 to async-await. I somehow thought async-std was the successor of tokio and ported everything to async-std. 80% in, I noticed that my hyper dependency requires tokio and that it's not possible to replace tokio with async-std without also replacing hyper. Also, tokio and async-std try to solve the same problem. So I started a journey into the inners of the rust async story to find out if it is possible to use both tokio and async-std at the same time. (tl;dr: it is). I had heard of reactors and executors before, but there was much new stuff to discover.

@tallclair
tallclair / kubectl-cp.sh
Last active January 18, 2024 22:19
kubectl cp equivalents
# Copy /tmp/foo_dir local directory to /tmp/bar_dir in a remote pod in the default namespace
kubectl cp /tmp/foo_dir <some-pod>:/tmp/foo_dir
tar cf - /tmp/foo_dir | kubectl exec -i <some-pod> -- tar xf -
# Copy /tmp/foo local file to /tmp/bar in a remote pod in a specific container
kubectl cp /tmp/foo <some-pod>:/tmp/foo -c <specific-container>
tar cf - /tmp/foo | kubectl exec -i <some-pod> -c <specific-container> -- tar xf -
# Copy /tmp/foo local file to /tmp/bar in a remote pod in namespace <some-namespace>
kubectl cp /tmp/foo <some-namespace>/<some-pod>:/tmp/foo
@LozanoMatheus
LozanoMatheus / 01-bash_http.sh
Last active August 24, 2023 13:24
A simple request - HTTP request with native Bash and without curl/wget/*
#!/usr/bin/env bash +x
## Do you need to test your exposed app but you don't have curl/wget/* installed?
## The ":" is a built-in command and it works similar to true. Let's say, ":" is more portable than "true"
## Simple and easy
:> /dev/tcp/localhost/22
## Why using timeout? If any side has a firewall and it's dropping the packages, the request will take ~80 seconds to get the timeout.
@mohanpedala
mohanpedala / bash_strict_mode.md
Last active April 23, 2024 11:47
set -e, -u, -o, -x pipefail explanation