Skip to content

Instantly share code, notes, and snippets.

View telekosmos's full-sized avatar
💭
👻

Guillermo C. Martínez telekosmos

💭
👻
View GitHub Profile
@telekosmos
telekosmos / file-ocurrences.sh
Created January 14, 2020 13:02
[shell] Rank word occurences in a text file
iconv -c -t UTF-8 <file> | tr -dC '[:print:]\t\n' | awk '{for(i = 1; i <= NF; i++) {a[$i]++}} END {for(k in a) if(a[k] >= 1) {print k, a[k]}}' | sort -n -k2 --reverse | less
@telekosmos
telekosmos / deconstructing-flatten.js
Last active September 29, 2019 18:31
es6 - One level deep object flattening
const fn = ({ a, o }) => ({a, ...o});
const obj = { a:1, o: { b: 2, c: 3 } };
const r = fn(obj);
// r = { a: 1, b: 2, c: 3 }
@telekosmos
telekosmos / es6pojos.js
Last active August 23, 2019 07:57
ES6 POJOs
// doesn't work
const counter = {
val: 0,
next: () => ++this.val, // eslint-disable-line no-plusplus
};
counter.val; // 0
counter.next();
counter.val; // 0
// DOES work
@telekosmos
telekosmos / snapshot_utility.py
Created July 29, 2019 15:23 — forked from tomconte/snapshot_utility.py
Sample Python script to manage Azure Blob Storage snapshots: list snapshots, take a snapshot, delete a snapshot, copy a snapshot to a new Blob.
#!/usr/bin/python
from azure.storage import BlobService
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("container", help="the blob container")
parser.add_argument("blob", help="the blob name")
parser.add_argument("-s", "--snapshot", help="take a new snapshot", action="store_true")
parser.add_argument("-d", "--delete", help="delete a snapshot")

Unix shell command output redirects

  • > file redirects stdout to file
  • 1> file redirects stdout to file
  • 2> file redirects stderr to file
  • &amp;&gt; file redirects stdout and stderr to file
@telekosmos
telekosmos / kafka-commands.md
Last active May 22, 2019 12:26
Kafka tools handy commands
@telekosmos
telekosmos / curl.md
Created April 11, 2019 13:08 — forked from subfuzion/curl.md
curl POST examples

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.

@telekosmos
telekosmos / drop-index.md
Created February 14, 2019 15:38
MsSQL 😩 things

You'll get the same exception if the index was created defining a PRIMARY KEY or UNIQUE constraint (ref).

In that case the simple solution is to use the ALTER-TABLE-command instead:

ALTER TABLE tbl1 DROP CONSTRAINT ix_cox

@telekosmos
telekosmos / remove-node_modules.sh
Created January 14, 2019 20:47
Remove node_modules recursively
find . -name "node_modules" -type d -prune -exec rm -rf '{}' +
/*
* AWS Sdk KMS spike: (assuming node v6.6+)
* 1 - Create master key at KMS
* 2 - Copy alias or ARN
* 3 - run this i.e.
* $ node spike.js KEY_ALIAS YOUR_PLAINTEXT_TO_ENCRYPT
*
* Taken from https://gist.github.com/raytung/f7dc78bb4310d02217111246da8cfdb3
*/
const AWS = require('aws-sdk');