Skip to content

Instantly share code, notes, and snippets.

@dhl
dhl / Native Solana security issues
Created November 25, 2024 15:22 — forked from zigtur/Native Solana security issues
Solana - Security for Builders
# Native Solana security issues
This gist shows 3 vulnerable code examples in Native Rust Solana programs.
======================================================================
ERROR: test_run_hello_workflow_incompatible_0_request_through_stdin (tests.functional.test_cli.TestCliWithHelloWorkflow)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/nix/store/8h7vxyym56zxf03bb3w8dwifr9pv2pan-python2.7-parameterized-0.7.0/lib/python2.7/site-packages/parameterized/parameterized.py", line 518, in standalone_func
return func(*(a + p.args), **p.kwargs)
File "/build/source/tests/functional/test_cli.py", line 149, in test_run_hello_workflow_incompatible
p = subprocess.Popen([self.command_name], env=env, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
File "/nix/store/gy3r9y4rvs7rlxm88az4lxqsrr2020f2-python-2.7.15/lib/python2.7/subprocess.py", line 394, in __init__
errread, errwrite)
@dhl
dhl / default.nix
Last active April 3, 2019 02:19
Compiling rust against musl target with Nix. Adapted from https://github.com/mozilla/nixpkgs-mozilla/issues/91#issuecomment-464483970
{ pkgsPath ? <nixpkgs>, crossSystem ? null }:
let
mozOverlay = import (
builtins.fetchTarball https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz
);
pkgs = import pkgsPath {
overlays = [ mozOverlay ];
inherit crossSystem;
};
@dhl
dhl / nixos-install-encrypted-root.sh
Created October 31, 2018 02:41 — forked from sveitser/nixos-install-encrypted-root.sh
Installs nixos on encrypted root from live CD.
#!usr/bin/env bash
#
# Installs nixos with full disk encrypted root partition.
#
# - Prompts for password initially, after that no interaction should
# be required.
# - At the end it will prompt for a root password, could not make
# echo-ing it into nixos-install work.
# - Reserves 550MB for boot partition, rest for the root volume.
# - After booting, log in as root user and set password for normal user.

Naming Conventions in Code

Verify

Tests if some subject (object or data) passes the correctness definition for some type. Returns true if the test passes, and false otherwise.

Validate

Tests if some subject (object or data) passes the correctness definition for some type. Throws an exception if the subject did not pass the test. The test is not required to return any meainingful value if the test pases.

@dhl
dhl / nix_channel_age.sh
Created October 19, 2018 02:43
Find out how old a Nix channel is
curl -sS http://howoldis.herokuapp.com/api/channels | jq -c 'map(select(.name == "nixos-unstable") | .humantime) | .[]'
const validationFunctionMetadataKey = Symbol.for('validate::func')
function makeParamValidator(validator: Function) {
return (
target: Object,
propertyKey: string | symbol,
parameterIndex: number
) => {
let existingValidationParameters: Map<any, Function> =
Reflect.getOwnMetadata(
package main
import (
"context"
"log"
"net/http"
"os"
"os/signal"
"time"
)
@dhl
dhl / cljs.sh
Last active July 5, 2018 06:41
Minimal example ot run ClojureScript reopl on Nix with nix-shell
echo '{:deps {org.clojure/clojurescript {:mvn/version "1.10.339"}}}' > deps.edn && nix-shell -p clojure rlwrap nodejs-8_x
# once nix-shell loads up
# $ clj -m cljs.main --repl-env node
@dhl
dhl / riot_key_verification.js
Last active July 3, 2018 06:07
Quick and dirty hack to verify a long list of devices in Riot's "Unknown Device" dialog.
/*
Quick and dirty hack. USE AT YOUR OWN RISK.
*/
function clickVerifyInDialog() { $('.mx_Dialog_primary').click() }
function verifyFirstKey() { $('.mx_UnknownDeviceDialog .mx_MemberDeviceInfo_verify').click() }
function hasKeyToVerify() { return $('.mx_UnknownDeviceDialog .mx_MemberDeviceInfo_verify') }
function verificationIsDisplayed() {
return $('#mx_BaseDialog_title').innerHTML == 'Verify device'
}