Skip to content

Instantly share code, notes, and snippets.

View arielshaqed's full-sized avatar
💭
🦎 lakeFSing FTW 🏁

Ariel Shaqed (Scolnicov) arielshaqed

💭
🦎 lakeFSing FTW 🏁
View GitHub Profile
@arielshaqed
arielshaqed / rsyslog.conf
Created November 27, 2017 08:59
Report from RSyslog to Loggly, handling severity/priority for JSON and logrus.
module(load="mmjsonparse")
set $.computed_pri = $pri;
# TODO: Better ISO-8601 capture (e.g. this one doesn't handle some leap second representations).
set $.inner_level = re_extract($msg, '^ *time="[1-9][0-9]{3,}-(1[12]|0[1-9])-(3[01]|[12][0-9]|0[1-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])Z" +level=([a-z]+)', 0, 6, '');
if ($.inner_level == '') then {
action(type="mmjsonparse" cookie="")
if $parsesuccess == 'OK' then set $.inner_level = $!level;
@arielshaqed
arielshaqed / as-helm-other.el
Created January 11, 2018 13:16
Emacs: helm commands with other-window defaults
;;; Versions of helm commands that usefully replace `find-file-other-window'
;;; and `switch-to-buffer-other-window'. They work by replacing the default
;;; action and calling the actual helm functions.
(defun as-alist-move-cdr-first (alist cdr-value)
"Returns a copy of alist, but with the (first) element with CDR cdr-value at its head."
(let ((first (rassoc cdr-value alist)))
(if first
(cons first (map-remove #'(lambda (key value) (equal value cdr-value)) alist))
alist)))
@arielshaqed
arielshaqed / feedback.ts
Last active July 16, 2018 10:41
RxJS feedback loop using Rx.Subject
// DO NOT SUBMIT: Code for teaching ariels to feed state back through
// RxJS.
import { test } from 'ava';
import * as Rx from 'rxjs';
import { List } from 'immutable-sorted';
class State {
private constructor(private lastN: List<number>, private num: number) {}
// Leak memory using Rx.bufferTime.
import * as Rx from 'rxjs';
import * as op from 'rxjs/operators';
declare var window: any;
function getHeap() {
return process.memoryUsage().heapUsed;
}
@arielshaqed
arielshaqed / size.py
Last active January 1, 2019 15:23
Resize an iTerm* or xterm or ...
#!/usr/bin/env python2
# Generates a control sequence for resizing a window. These are all
# described at https://invisible-island.net/xterm/ctlseqs/ctlseqs.html.
import click
@click.command()
@click.option('--rows', default=60, help='Number of rows.')
@click.option('--cols', default=80, help='Number of columns.')
@arielshaqed
arielshaqed / cleanup-atlas.ts
Created December 25, 2019 08:17
Recursively clean up old projects (*including* their clusters) from MongoDB Atlas: anything starting `autoAtlas-`.
import * as baseRequest from 'request-promise-native';
import { StatusCodeError } from 'request-promise-native/errors';
import { concurrently, backoff } from '@binaris/nodeutils';
const orgId = process.env.ATLAS_ORG_ID
const publicKey = process.env.ATLAS_PUBLIC_KEY;
const privateKey = process.env.ATLAS_PRIVATE_KEY;
const concurrency = parseInt(process.env.ATLAS_CONCURRENCY || '30', 10);
const request = baseRequest.defaults({
((10*(9*8*(7-6)-5)+4)*3-2)*1
((10*(9*8*(7-6)-5)+4)*3-2)/1
((10*(9*8-(7-6)*5)+4)*3-2)*1
((10*(9*8-(7-6)*5)+4)*3-2)/1
((10*(9*8/(7-6)-5)+4)*3-2)*1
((10*(9*8/(7-6)-5)+4)*3-2)/1
((10*9+8)*7-(6+5*4/3))*(2+1)
((10*9+8)*7-6-5*4/3)*(2+1)
((10*9+8)/7+6)*(5*4*(3+2)+1)
((10*9+8*(7*(6+5)-4))*3-2)*1
@arielshaqed
arielshaqed / method-keys.ts
Last active October 26, 2022 12:23
Extract keys of methods of TypeScript type
// https://www.typescriptlang.org/play/#code/C4TwDgpgBAshwAsD2ATA0hEBnA8gJwDkIA3CPAHgBUA+KAXigG8AoKNqAbTSgEsA7KAGtMSAGZRKAXQBcErpKgQAHsAh8UWKADEArnwDGwHkgEB+KN1l8SZANzMAvs1CRY8ZOkxYqtBnESoGNj4RKQUNBzCIGISkvbM-Kp4ogCG+tAAkkys7HxWOgC2AEZ2OWyiABQp+cVkAJSyWMB4-ADm9uxQrRUNUMRIPCj2Ti7QWvRuAZ7Y5BnUtmwA9ItQAESiq1AAPmutq8xAA
type MethodKeysOrNever<T> = {
[K in keyof T]: T[K] extends Function ? K : never;
}
type MethodKeys<T> = MethodKeysOrNever<T>[keyof T];
@arielshaqed
arielshaqed / sim.go
Last active January 12, 2021 11:44
simulate range sizes with a log-normal path size distribution
package main
import (
"fmt"
"math"
"time"
"golang.org/x/exp/rand"
"gonum.org/v1/gonum/stat/distuv"
@arielshaqed
arielshaqed / magit-origin-master.el
Created February 2, 2021 07:54
add "r o" and "d o" to magit: diff and rebase with origin/master
;;; Define "r o" (an "o" suffix) for "magit rebase onto origin/master"
(require 'magit)
(transient-define-suffix as-magit-rebase-onto-origin-master (args)
"Rebase the current branch onto origin/master.
TODO(ariels): Make it better and also document it."
:if 'magit-get-current-branch
:description "origin/master"
(interactive (list (magit-rebase-arguments)))
(magit-git-rebase "origin/master" args))