Skip to content

Instantly share code, notes, and snippets.

@gromnitsky
gromnitsky / twitter-stats
Created January 6, 2021 08:58
Twitter stats using gnuplot, json & gnu make
#!/usr/bin/make -sf
$(if $(i),,$(error Usage: twitter-stats i=twitter-YYYY-MM-DD-sha256.zip [lang|users|1.png|1.svg]))
n=5
top: tweets.json
json -e 'this.tweet.permalink = `https://twitter.com/i/web/status/$${this.tweet.id}`; this.tweet.rating = Number(this.tweet.favorite_count) + Number(this.tweet.retweet_count)' -c 'this.tweet.rating > 0' < $< | json -Ae 'this.sort((a,b)=> a.tweet.rating-b.tweet.rating)' | json -Ae 'this.q = this.slice(-$(n))' q | json -e 'this.q = {rating: this.tweet.rating, date: this.tweet.created_at, text: this.tweet.full_text, permalink: this.tweet.permalink}' -a q
lang: tweets.json; json -a tweet.lang < $< | $(aggregate) | $(sort)
@gromnitsky
gromnitsky / nic
Created March 14, 2019 23:01
print all the relevant info about all the nics; useful for machines w/ multiple network cards; linux only
#!/bin/sh
errno=0
sys=/sys/class/net
# $1 == nic
dump() {
[ -d "$sys/$1" ] || { echo "$1 is absent" 1>&2; errno=2; return; }
echo Name "$1" | pp
#!/usr/bin/make -f
# Requires nokogiri & gnuplot
#
# curl http://feeds.5by5.tv/b2w | ./podcast-dow 1.png [title=hello]
plot = @nokogiri -e 'puts $$_.css("item pubdate").map{|n| Date.parse(n).strftime("%Y-%m-%d %u %a")}' | cat <(echo "$$script") - | gnuplot -e 'set term $1;' - > $@
%.png:; $(call plot,png)
%.svg:; $(call plot,svg)
#!/bin/sh
# -*-coding:utf-8-unix-*-
usage() { echo Usage: ipconfig \| `basename $0` [-v] [-m NUM] pattern 1>&2; exit 2; }
while getopts "vm:" o; do
case $o in
v) opt_v=! ;;
m) opt_m=$OPTARG ;;
*) usage
@gromnitsky
gromnitsky / headlines5.js
Created April 1, 2018 17:50
Use FeedParser as a transform stream
let Transform = require('stream').Transform
let FeedParser = require('feedparser')
let pump = require('pump')
class Filter extends Transform {
constructor(articles_max, feedparser) {
super()
this._writableState.objectMode = true // we can eat objects
this.articles_max = articles_max
this.articles_count = 0
@gromnitsky
gromnitsky / gmake-patsubst.c
Last active July 9, 2021 05:00
An extract of patsubst function from GNU Make
/*
An extract of patsubst function from GNU Make 4.2.90
(6f339b22eb87dc80d1037ccb04c787d156db0e8f)
$ cc gmake-patsubst.c -o gmake-patsubst
$ ./gmake-patsubst %.c %.o 'foo.c bar.c'
foo.o bar.o
*/
#include <stdio.h>
@gromnitsky
gromnitsky / read-aloud-sapi.ps1
Created August 10, 2016 11:52
Read stdin & feed it to Windows system TTS engine via SAPI
<#
.SYNOPSIS
Read stdin & feed it to the system TTS engine.
#>
param(
# Sets the speaking rate in real time.
[int] [ValidateRange(-10, 10)] $r = 0,
# Specify a voice (use -l to get the valid names).
[string] $voice = "",
# Print available voices.
@gromnitsky
gromnitsky / molloy.rb
Created December 23, 2011 16:22
Molloy Problem
#!/usr/bin/env ruby
# -*-ruby-*-
require 'pp'
require 'minitest/autorun'
class Pocket
MAX = 16
attr_reader :stones, :name
@gromnitsky
gromnitsky / unity_fixture_runner
Created May 18, 2011 18:46
Tests 'runner' generator for unity_fixture (not plain Unity) framework, http://embunity.sourceforge.net
#!/usr/bin/env ruby
# -*-ruby-*-
require 'erb'
class UnityFixture
def initialize
@tests = {}
end
@gromnitsky
gromnitsky / Rakefile
Created May 13, 2011 20:36
Ruby 'require' time of blank .rb files
# -*-ruby-*-
require 'benchmark'
STEP = 500
ROUNDS = 8
FILES = 'rec-files'
FILES_N = (1..ROUNDS).inject(0) {|i,j| i + j*STEP }
#FILES_LEN = Math.log(FILES_N, 10).floor + 1 # works only in 1.9
FILES_LEN = FILES_N.to_s.size