Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:
Doing stuff

Srinath Sankar Checksum

:octocat:
Doing stuff
View GitHub Profile
View .zshrc.local.sh
# git
alias gs='git status'
alias gd='git diff'
alias gds='git diff --staged'
alias gcom='git checkout master'
alias gco='git checkout'
alias gp='git pull'
alias git-deleted='git log --diff-filter=D --summary'
# utils
@Checksum
Checksum / main.rs
Created Sep 13, 2020
Syscheck rust lifetime issue
View main.rs
use crate::core::{Check, Error as CheckError};
use iced::{Application, Command, Container, Element, Settings, Text};
fn main() -> iced::Result {
Syscheck::run(Settings::default())
}
#[derive(Debug)]
pub enum Syscheck {
Setup(SetupState),
@Checksum
Checksum / assert.jq
Last active Sep 2, 2021
Assertion library for jq
View assert.jq
# A simple assertion library for jq (https://github.com/stedolan/jq)
# Author: Srinath Sankar
def assert(expr; msg; level):
if expr then
.
else
. |= . + [{ level: level, message: msg }]
end;
@Checksum
Checksum / diff-patch.jq
Last active Aug 26, 2021
JSON diff and patch for jq
View diff-patch.jq
# JSON diff and patch for jq (https://stedolan.github.io/jq/)
# Author: Srinath Sankar
#
# Usage:
# diff: jq -sS 'include "diff-patch"; diff' a.json b.json > patch.json
# patch: jq -sS 'include "diff-patch"; patch' a.json patch.json
#
# Caveats: tested only with top level objects using jq 1.6
def flatten_obj:
@Checksum
Checksum / websocket_proxy.js
Last active Aug 13, 2021
Intercepting WebSockets in the browser using JavaScript
View websocket_proxy.js
const WebSocketProxy = new Proxy(window.WebSocket, {
construct(target, args) {
console.log("Proxying WebSocket connection", ...args);
const ws = new target(...args);
// Configurable hooks
ws.hooks = {
beforeSend: () => null,
beforeReceive: () => null
};
@Checksum
Checksum / snippets.sh
Last active Mar 3, 2020
Bash snippets
View snippets.sh
#!/bin/bash
# Dynamic bracket expansion
eval echo "{1..3}"
eval echo "foo-{bar,baz}-{1..3}"
# Merge JSON objects
merged="$(jq -ers '.[0] * .[1]' <(echo '{"name": "foo"}') <(echo '{"age": "baz"}') 2>/dev/null)"
# Check if string is valid JSON
@Checksum
Checksum / bitwarden_rs.sh
Last active Aug 19, 2021
Cross compiling bitwarden_rs for Raspberry Pi
View bitwarden_rs.sh
# Requires git and docker
# clone bitwarden_rs
git clone https://github.com/dani-garcia/bitwarden_rs
cd bitwarden_rs
# Use rust docker container to build everything
docker run --rm -it -v `pwd`:/bitwarden rust bash
# Download pi tools and openssl
@Checksum
Checksum / stack.yaml
Created Jul 31, 2019
Elm 0.19.1 stack.yaml
View stack.yaml
flags: {}
packages:
- .
extra-deps:
- language-glsl-0.3.0@sha256:85c1e7bf2cf5d6e604b7a2899c27e2935033425944db200798e57849e64d4c81
- time-1.9.2@sha256:874e07fb970531b9dcd814f74e00f253ce2f22ccd8272a6c4c137ee9040237fb
resolver: lts-12.14
@Checksum
Checksum / postgresql.sql
Last active Jan 14, 2020
PostgreSQL handy queries
View postgresql.sql
-- Get size of database
SELECT pg_size_pretty(pg_database_size('database-name'));
-- Set the current session as read only
SET SESSION CHARACTERISTICS AS TRANSACTION READ ONLY;
-- Locks
-- https://www.postgresql.org/docs/10/functions-admin.html#FUNCTIONS-ADVISORY-LOCKS
SELECT pg_try_advisory_lock(123123213123) as lockObtained;
@Checksum
Checksum / sqlcmd.sql
Created Apr 9, 2019
sqlcmd cheat sheet
View sqlcmd.sql
-- type 'go' to execute the block
-- List all tables
1> select * from information_schema.tables;
-- Describe table
1> exec sp_columns table_name;