Skip to content

Instantly share code, notes, and snippets.

View gkastrinis's full-sized avatar
🦄
Chasing Unicorns

George Kastrinis gkastrinis

🦄
Chasing Unicorns
View GitHub Profile
#include <stdio.h>
#include <stdlib.h>
// num is the original number
// i is the current digit
// digits is the total number of digits in num
// mask is a number with 'digits' length of 1 and 0
void solve(int num, int i, int digits, int mask, int maxOne) {
// combine mask and num and print only the digits of num
// in the places where mask has 1
def hiragana = [
//kana
'a':'あ','i':'い','u':'う','e':'え','o':'お',
'ka':'か','ki':'き','ku':'く','ke':'け','ko':'こ',
'sa':'さ','shi':'し','su':'す','se':'せ','so':'そ',
'ta':'た','chi':'ち','tsu':'つ','te':'て','to':'と',
'na':'な','ni':'に','nu':'ぬ','ne':'ね','no':'の',
'ha':'は','hi':'ひ','fu':'ふ','he':'へ','ho':'ほ',
'ma':'ま','mi':'み','mu':'む','me':'め','mo':'も',
'ya':'や','yu':'ゆ','yo':'よ',
@gkastrinis
gkastrinis / bst_to_cdll.c
Created March 22, 2021 14:49
Binary Search Tree to Circular Doubly Linked List
#include <stdio.h>
#include <stdlib.h>
typedef struct Node {
int data;
struct Node* left;
struct Node* right;
} Node;
void add_tree(Node **root, int v) {
@groovy.transform.Canonical
class Candidate {
def result
def invalids = []
}
def brute(def list, def ok, def okInOrder, def candidates) {
def newCandidates = []
candidates.findResults { candidate ->

Dionysis Zindros, March 2017 - Attack failed

Dionysis asked me whether I could help him with a simple python script he was working on. He claimed he was trying to get the plain text from a ciphertext, but he was getting a weird runtime error message.

He gave me a gist with the script and wnated to know if I could see something he was missing. He suggested I run the script and see the message myself.

@gkastrinis
gkastrinis / post3.md
Last active June 3, 2020 13:50
SSH Tunneling (a.k.a. Port Forwarding)

SSH Tunneling (a.k.a. Port Forwarding)

In general, SSH tunneling creates a secure connection between a local computer and a remote machine through which services can be relayed (the important part). Because the connection is encrypted, SSH tunneling is useful for transmitting information that uses an unencrypted protocol, such as IMAP, VNC, or IRC (the not-so-important part).

A case where I found this to be a useful technique was when I had a remote machine running a web server but because of various reasons (e.g. security concerns) there was no public open port available (that I could use). If such a port existed (e.g. 9876), I could simply access the web server from my favorite web browser just by providing the appropriate URL address (e.g. http://example.com:9876). But fortunately enough, I had SSH access to that remote machine.

This is how it works:

#include <stdio.h>
#include <stdint.h>
#include <string.h>
void magic(char* str, int i, int changesLeft) {
if (changesLeft == 0) {
printf("%s\n", str);
return;
}
if (i < 0) return;
@gkastrinis
gkastrinis / ping_uoa.java
Last active January 31, 2016 19:54
PingUoA
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
public class Main {
final static int SLEEP_TIME = 7;
public static void main(String[] args) {
@gkastrinis
gkastrinis / post2.md
Last active November 15, 2022 15:43
Tablet as second PC monitor

Tablet as second PC monitor

Lately I've been thinking about using my old nexus 7 (from 2012) as a second PC monitor.

I've read articles regarding android apps for this purpose as well as comments from Google Play. Some examples can be found here and here. Bottom line, you have to pay and most likely you will end up struggling with (huge?) lag and/or compatibility issues. I tried splashtop but it felt lacking in some way, it was just mirroring my main monitor and it was free just for the first 5 minutes.

@gkastrinis
gkastrinis / post1.md
Last active July 8, 2018 11:16
Unspecified (or undefined) behavior & sequence points in C++

Unspecified (or undefined) behavior & sequence points

Assume the following code snippet of test.cpp. Our goal was to read integers from stdin and map them to the order in which they first appeared in our input. Keep in mind this is just a test and probably there are better ways to implement the intended behavior of this cut-down version.

If we use g++ to compile our code we get the following output. This was not the output we were expecting.