Skip to content

Instantly share code, notes, and snippets.

View pingiun's full-sized avatar

Jelle Besseling pingiun

View GitHub Profile
@pingiun
pingiun / emojiencode.py
Last active September 22, 2022 18:36
Emojiencode can be used to encode a hash in emoji, like Telegram is doing for secret voice calls
# -*- coding: utf-8 -*-
# This alphabet is handpicked to be visually distinctive
_alphabet = ['☕️', '🐜', '✉️', '🎋', '👟', '📺', '😅', '✌️', '🌰', '🍇',
'🐶', '👢', '💉', '💈', '⚡️', '🌹', '🗽', '👌', '💔', '🎈',
'🥑', '⌚️', '🚿', '🐫', '🔧', '🔌', '😈', '💳', '😊', '👍',
'🍞', '😘', '🎯', '⛄️', '🔦', '🐳', '🍌', '‼️', '🥝', '✂️',
'🎄', '💥', '🍷', '🚦', '📬', '🎡', '🎆', '🔍', '🍻', '🏭',
'🎶', '💡', '🏄', '👂', '🗡️', '🍒', '👑', '🚃', '🙏', '❌',
'💾', '🙋', '👸', '🔪', '👎', '🌊', '🍕', '⚽️', '🎁', '🏈',
@pingiun
pingiun / DeadMansSwitch.sol
Last active August 2, 2020 11:15
Ethereum contract which only pays back if you continue to activate it
pragma solidity ^0.4.0;
contract Ownable {
/// @dev `owner` is the only address that can call a function with this
/// modifier
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
import re
import sys
from datetime import datetime
from b2.api import B2Api
def parse(inp, mformat=None, thing=None):
if thing is None:
thing = 'th'
if mformat is None:
from telegram.ext import Updater, CommandHandler, MessageHandler
from sqlalchemy import Column, BigInteger
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from sqlite3 import IntegrityError
import logging
import random
from sqlalchemy import Column, PickleType
def upsert(obj):
"""Inserts the `obj` or updates if it already exists
Postgresql is the only database that supports upserts like this, but sqlite is used locally so a "hack" is used to support
an alternative check and update/insert method. This cannot be used when multithreading."""
# SQLalchemy model objects have the table object in __table__
table = obj.__table__
# Filter out private values from the object
extern crate tokio;
extern crate dhcp_proto;
use std::io;
use tokio::codec::{Decoder, Encoder};
use bytes::{BytesMut};
use dhcp_proto::{DHCPMessage, nom, parse_dhcp};
use dhcp_proto::builder::DHCPMessageBuilder;
@pingiun
pingiun / configuration.nix
Last active April 13, 2019 11:47
The nixos configuration file I use to use mac.jelle.space for my macbook
let
wireguardPort = 51820;
tunnels = [ {
ipv4Addr = { addr = "195.201.249.203"; suffix = 32; };
ipv6Addr = { addr = "2a01:4f8:c2c:2b57::2"; suffix = 128; };
wgPublicKey = "3WWr1zr3ry6KeAwr3Cw3mQsnBeLLUYs1DGa7iEwyAWA=";
} ];
mkAddrWithSuffix = (x: "${x.addr}/${toString x.suffix}" );
@pingiun
pingiun / newsletterintro.sh
Last active July 20, 2020 14:54
Generate newsletter introduction piece, license: GPL-3.0
#!/usr/bin/env bash
set -euo pipefail
get_events() {
lang_website=$1
export LC_ALL=$2
for pk in $(curl -H "Accept-Language: $lang_website" "https://thalia.nu/api/v1/events/" 2>/dev/null | jq '.|=sort_by(.start)|.[].pk'); do
event=$(curl -H "Accept-Language: $lang_website" "https://thalia.nu/api/v1/events/$pk/" 2>/dev/null)
@pingiun
pingiun / bisq.2m.sh
Last active July 30, 2020 13:39
Get the latest BTC price from Bisq and compare with Coinbase. This script is a Bitbar plugin: https://getbitbar.com
#!/usr/local/bin/bash
# Donations are always apreciated: 337tQLpE6u7itDzju1d3zdnWBr1qR9mNNW
# Can be changed to any currency both Bisq and Coinbase support (usd, eur are tested)
currency="eur"
alt_currency="usd"
tickers=$(curl -sS "https://markets.bisq.network/api/ticker/")
coinbase=$(curl -sS "https://api.coinbase.com/v2/prices/BTC-${currency}/buy")
@pingiun
pingiun / Habits.sol
Created August 21, 2020 17:00
Habits testing
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.7.0;
import "Owner.sol";
/**
* Track habits with a financial stake if you fail.
*/
contract Habits is Owner {
struct Habit {