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
@gkastrinis
gkastrinis / post0.md
Last active November 21, 2015 03:46
Hello World

Code blogging using GitHub gists

Every now and then I might find something interesting related to coding. I might spent some time doing some research, and maybe write about it in an email or in a post in a course-oriented forum. But in the end it is probably forgotten and should the need arises for me to mention my findings again, I have to do a great portion of the process again.

Recently, I thought about using GitHubGist as a blogging platform of some kind. They provide all the nice things you might be familiar with in GitHub, there is

@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) {
#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;

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 / 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.

@groovy.transform.Canonical
class Candidate {
def result
def invalids = []
}
def brute(def list, def ok, def okInOrder, def candidates) {
def newCandidates = []
candidates.findResults { candidate ->
@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:

@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) {
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':'よ',
#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