Skip to content

Instantly share code, notes, and snippets.

View Checksum's full-sized avatar
:octocat:
Doing stuff

Srinath Sankar Checksum

:octocat:
Doing stuff
View GitHub Profile
@Checksum
Checksum / diff-patch.jq
Last active August 26, 2021 01:04
JSON diff and patch for 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 / bitwarden_rs.sh
Last active August 19, 2021 02:39
Cross compiling bitwarden_rs for Raspberry Pi
# 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 / main.rs
Created September 13, 2020 02:02
Syscheck rust lifetime issue
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 / postgresql.sql
Last active January 14, 2020 06:15
PostgreSQL handy queries
-- 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 / postgresql-json-queries.md
Last active January 14, 2020 06:11
Collection of queries to manipulate JSONB in PostgreSQL
CREATE TABLE users(
  id serial not null primary key,
  username text not null
);

CREATE TABLE tweets(
  id serial not null primary key,
  content jsonb default('{}')
);
@Checksum
Checksum / stack.yaml
Created July 31, 2019 00:40
Elm 0.19.1 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 / sqlcmd.sql
Created April 9, 2019 00:53
sqlcmd cheat sheet
-- type 'go' to execute the block
-- List all tables
1> select * from information_schema.tables;
-- Describe table
1> exec sp_columns table_name;
@Checksum
Checksum / regex.md
Created March 11, 2019 23:47
Regex Tricks
  • Split every character: "something".split(/(?!^)/)

  • Never split: "something".split(/^.$/)

@Checksum
Checksum / building-elm.md
Last active February 27, 2019 05:35
Building Elm 0.19
  • Clone elm/compiler
  • Install stack
  • Install required version of cabal using stack --resolver lts-9 install cabal-install (commercialhaskell/stack#3453 (comment))
  • PATH=~/.local/bin:$PATH stack init --solver to install the required version of GHC
  • PATH=~/.local/bin:$PATH stack build --flag elm:dev to build
@Checksum
Checksum / JSON_response.js
Created July 27, 2012 06:36
Node.js get JSON response
require('http').request({
host: 'example.com',
path: '/path/to/get',
method: 'GET'
}, function(res) {
res.setEncoding('utf8');
var body = '';
res.on('data', function(chunk) {
body += chunk;
});