Skip to content

Instantly share code, notes, and snippets.

View savely-krasovsky's full-sized avatar

Savely Krasovsky savely-krasovsky

View GitHub Profile

Keybase proof

I hereby claim:

  • I am l11r on github.
  • I am l11r (https://keybase.io/l11r) on keybase.
  • I have a public key ASBd9ZJKPqfys-B12PWDpjBd7kixBYoSUZthDf1DPSQphwo

To claim this, I am signing this object:

Golang Type Switch - Arbitrary JSON Array Parsing

I'm writing this mostly as a reference for myself. This could also be helpful to people who are new to GO.

Note 1:

Until Problem 3 we will assume we are dealing with a JSON for which we know the data types of key,value pairs. Only in Problem 3 we will look at how Type Switch is used to parse a 100% arbitary JSON

Note 2:

I know the following examples given here can be easily solved by declaring approprite structs and just decoding the PUT JSON into them, but, as im not able to come up with a better scenario, im going to stick with this to explain arbitrary JSON parsing.

Keybase proof

I hereby claim:

  • I am lord-protector on github.
  • I am kraso (https://keybase.io/kraso) on keybase.
  • I have a public key ASBBl-NsYt44w44fQAlCQgpuDnp5B8wVd9UsXtSAEyUNGAo

To claim this, I am signing this object:

r.table('users').changes()
.filter(r.row('new_val')('profile').ne(r.row('old_val')('profile')))
.then(function (cursor) {
cursor.each(async function (err, row) {
if (err) new Error(err);
сonsole.log('Feed change detected!');
await setLocale({from: {id: row.old_val.id}})
if (row.old_val && row.new_val && row.old_val.profile && row.new_val.profile) {
@savely-krasovsky
savely-krasovsky / score.js
Last active October 16, 2023 13:07 — forked from fipso/score.js
Gamee Hacker Bot for Telegram
/**
* Created by fipso on 13.10.16.
*/
const CryptoJS = require('crypto-js');
const request = require('request-promise-native');
const TelegramBot = require('node-telegram-bot-api');
const bot = new TelegramBot('TOKEN', {polling: true});

Keybase proof

I hereby claim:

  • I am Lord-Protector on github.
  • I am kraso (https://keybase.io/kraso) on keybase.
  • I have a public key whose fingerprint is B8AA FC71 4640 A280 1A42 B36C D857 4D8C 8D86 5E4F

To claim this, I am signing this object:

@savely-krasovsky
savely-krasovsky / README.md
Last active August 28, 2024 08:57
Telegram webhooks with nginx reverse proxy

Make config file:

sudo nano /etc/nginx/sites-available/bot.conf

Then copy and paste bot.conf content and edit YOUR.DOMAIN strings. Now install Let's Encrypt on your server. For example in Debian you need to add jessie-backports and easily install it with apt-get:

sudo apt-get install -t jessie-backports letsencrypt

Then get cert for you domain:

sudo apt-get update
sudo apt-get install -t jessie-backports letsencrypt
sudo letsencrypt certonly --standalone --email [email protected] -d example.com --rsa-key-size 4096
sudo openssl dhparam -dsaparam -out /etc/letsencrypt/live/example.com/dhparam.pem 4096
# '-dsaparam' key for very fast gen
sudo letsencrypt certonly --standalone --email [email protected] -d kraso.xyz --rsa-key-size 4096
sudo openssl dhparam -dsaparam -out /etc/letsencrypt/live/kraso.xyz/dhparam.pem 4096
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_session_cache shared:SSL:10m;
#!/bin/bash
# Trap Ctrl+C interupt
trap finish INT
exec_cmd_nobail() {
bash -c "$1"
}
exec_cmd() {