Skip to content

Instantly share code, notes, and snippets.

View aynik's full-sized avatar

Pablo Vazquez aynik

View GitHub Profile
@aynik
aynik / sun-zenith.sh
Created December 26, 2017 14:27
Sun zenith
#!/usr/bin/env bash
echo -n $(for l in $(for l in $(grep -Eo 'class=r>(.*)+</tr' <(curl -s "https://www.timeanddate.com/worldclock/sunearth.html")); do echo $l | grep -v "^<"; done | head -n2); do echo -n $(echo -n $l | sed 's/&nbsp;//g' | sed 's/West/W/' | sed 's/South/S/' | sed 's/North/N/' | sed 's/East/E/' | sed 's/<\/td><td>/0"/' | cut -d'>' -f2 | cut -d'<' -f1),; done | cut -d',' -f-2)
@aynik
aynik / nearest-city.js
Created December 26, 2017 20:49
Nearest city
#!/usr/bin/env node
const stdin = require('/usr/local/lib/node_modules/get-stdin')
const { parseDms } = require('/usr/local/lib/node_modules/dms-conversion')
const nearbyCities = require('/usr/local/lib/node_modules/aynik-nearby-cities')
const { NEAREST_CITY_DEBUG } = process.env
const getNearestCity = (latitude, longitude) => (
((data) => (
NEAREST_CITY_DEBUG
@aynik
aynik / p2p-coinflip.js
Last active January 15, 2018 14:30
Secure peer to peer coin flip over WebRTC
#!/usr/bin/env node
// dependencies: npm install --global wrtc
// usage: node p2p-coinflip.js [offer?]
const crypto = require('crypto')
const readline = require('readline')
const zlib = require('zlib')
const {
RTCPeerConnection,
@aynik
aynik / lnd.rb
Last active January 16, 2018 19:33
LND homebrew formula
class Lnd < Formula
desc "Lightning Network Daemon"
homepage "http://dev.lightning.community/"
url "https://github.com/lightningnetwork/lnd.git",
:branch => "master"
head "https://github.com/lightningnetwork/lnd.git"
version "0.3.0"
depends_on "go" => :build
@aynik
aynik / Account.js
Last active February 27, 2018 09:45
A prototype switching state machine
import StateMachine from './StateMachine'
class Account extends StateMachine {
constructor (initialState, initialBalance = 0) {
super(initialState)
this.balance = initialBalance
}
static get openStateMethods () {
return {
@aynik
aynik / ping-rng.js
Created March 31, 2018 10:27
Entropy from ping roundtrips
#!/usr/bin/env node
// requires: npm i -g get-stdin net-ping
// usage: ping-rng [bits?] < hosts
const stdin = require('/usr/local/lib/node_modules/get-stdin')
const ping = require('/usr/local/lib/node_modules/net-ping')
let sid = 0
const probe = async (hosts) => {
#!/usr/bin/env node
// discogs2spotify <spotify-playlist-id> <start-year>-<end-year> [discogs search params]
const args = require("minimist")(process.argv);
const Spotify = require("spotify-web-api-node");
const Discogs = require("disconnect").Client;
const Confirm = require("prompt-confirm");
const Prompt = require("prompt-base");
const DISCOGS_USER_TOKEN = "<DISCOGS_USER_TOKEN>";
const SOLID = "SOLID";
const LIQUID = "LIQUID";
const GAS = "GAS";
const transitions = {
[SOLID]: {
melt: LIQUID,
sublimate: GAS,
},
[LIQUID]: {
class FieldRoot(object):
def __init__(self, __id__, __parent_repr__=lambda x: x):
self.__id__ = __id__
self.__parent_repr__ = __parent_repr__
def __repr__(self):
return self.__parent_repr__(self.__id__)
def __embed__(self, child, __id__):
return child(__id__,
@aynik
aynik / models.py
Last active November 10, 2020 14:31
from django.db import models
class Item(models.Model):
title = models.CharField(max_length=128)
class GroupItems(models.Model):
group = models.ForeignKey(Group)
item = models.ForeignKey(Item)
class Group(models.Model):