Skip to content

Instantly share code, notes, and snippets.

Avatar
🦄
Chasing Unicorns

George Kastrinis gkastrinis

🦄
Chasing Unicorns
View GitHub Profile
View subseq.c
#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
View japrand.groovy
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 Mar 22, 2021
Binary Search Tree to Circular Doubly Linked List
View bst_to_cdll.c
#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) {
View numbers.groovy
@groovy.transform.Canonical
class Candidate {
def result
def invalids = []
}
def brute(def list, def ok, def okInOrder, def candidates) {
def newCandidates = []
candidates.findResults { candidate ->
View hack1.md

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 Jun 3, 2020
SSH Tunneling (a.k.a. Port Forwarding)
View post3.md

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:

View hamming.c
#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;
View ping_uoa.java
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 Jun 21, 2022
Tablet as second PC monitor
View post2.md

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 Jul 8, 2018
Unspecified (or undefined) behavior & sequence points in C++
View post1.md

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.