Skip to content

Instantly share code, notes, and snippets.

@gromnitsky
gromnitsky / twitter-stats
Created Jan 6, 2021
Twitter stats using gnuplot, json & gnu make
View twitter-stats
#!/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 Mar 14, 2019
print all the relevant info about all the nics; useful for machines w/ multiple network cards; linux only
View nic
#!/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
View podcast-dow
#!/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)
View ipgrep.sh
#!/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 Apr 1, 2018
Use FeedParser as a transform stream
View headlines5.js
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 Jul 9, 2021
An extract of patsubst function from GNU Make
View gmake-patsubst.c
/*
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 Aug 10, 2016
Read stdin & feed it to Windows system TTS engine via SAPI
View read-aloud-sapi.ps1
<#
.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.
View molloy.rb
#!/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
Tests 'runner' generator for unity_fixture (not plain Unity) framework, http://embunity.sourceforge.net
View unity_fixture_runner
#!/usr/bin/env ruby
# -*-ruby-*-
require 'erb'
class UnityFixture
def initialize
@tests = {}
end
@gromnitsky
gromnitsky / Rakefile
Created May 13, 2011
Ruby 'require' time of blank .rb files
View Rakefile
# -*-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