Skip to content

Instantly share code, notes, and snippets.

View feulf's full-sized avatar
🐢
slow and steady wins the race

Federico feulf

🐢
slow and steady wins the race
View GitHub Profile
@feulf
feulf / gist:4587709
Last active July 27, 2022 11:15
Keep the same PHP session between different domains

a simple idea is to force the session_id between the domains with an ajax call or an hidden iframe.

The concept is simple, you have [A,B,C] domains, where you create a script sid.php:

<?php session_id( $_GET['sid'] );

and a script sid_update.php that you have to place inside the PHP code of the front controller:

@feulf
feulf / random_nft.py
Created May 15, 2022 13:45
This code generates random patterns with ' ', +, and -
import random
symbols = ['-', '+', ' ', ' ', ' ', ' ']
def get_symbol(seed: int = 1):
# random.seed(seed)
r = int(random.random() * 1000)
return symbols[r % len(symbols)]
matrix = [[get_symbol(i + j) for i in range(40)] for j in range(20)]
from queue import Queue
class BinaryTree:
def __init__(self, value):
self.value = value
self.left_child = None
self.right_child = None
def insert_left(self, value):
import hashlib
hashed_list = [None] * 10 # create an array of None
def key_position(key):
string = key.encode() # convert to bytes
hashed_key = hashlib.sha256(string) # hash the string
hex_digest = hashed_key.hexdigest() # get the hex value
int_digest = int(hex_digest, 16) # convert to int
num = 0b000000001
#print(bin(num))
num = 0b000000001 << 1 # 0b10
#print(bin(num))
num = 0b000000001 << 2 # 0b100
#print(bin(num))
num = 0b000000001 >> 1 # 0b0
@feulf
feulf / data-types.py
Created October 29, 2019 20:42
Data Types in Python
# Boolean
# ------------------
print(True)
print(False)
print(type(True))
# Integers
# ------------------
# Python 3 has no limit for the data size. Aside the memory of course.
@feulf
feulf / bitcoin_attacker_success_probability.c
Created October 3, 2019 19:46
C code that shows the Poisson distribution of the probability to attack Bitcoin.
#include <math.h>
#include <stdio.h>
double AttackerSuccessProbability(double q, int z) {
double p = 1.0 - q;
double lambda = z * (q / p);
double sum = 1.0;
int i, k;
for (k = 0; k <= z; k++)
{
const functions = require('firebase-functions')
const admin = require('firebase-admin')
admin.initializeApp()
const db = admin.firestore()
const settings = {timestampsInSnapshots: true};
db.settings(settings);
@feulf
feulf / gist:4437179
Created January 2, 2013 19:30
This snippet is an HTML page with a Javascript that "emulate" Varnish loading the <esi:include> blocks client side. The idea is to create a dynamic website in HTML loaded in S3, with groundbreaking performances. Hope this experiment will inspire better solutions.
<!DOCTYPE html>
<html>
<head></head>
<body>
<esi:include src="head.html" alt="not-found.html" onerror="continue"></esi:include>
<esi:include src="body.php" alt="not-found.html" onerror="continue"/>
<h2>HTML</h2>
</esi:include>
<esi:include src="footer.html" alt="not-found.html" onerror="continue"/></esi:include>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
@feulf
feulf / lightning_network_workshop_1_commands.md
Last active April 10, 2018 05:10
Workshop Series 1: Lightning Network

Lightning Network Workshop Series 1

  1. Run btcd
./btcd --simnet --rpcuser=kek --rpcpass=kek --txindex --connect=YOUR_IP
  1. Run lnd
./lnd --bitcoin.active --bitcoin.simnet --bitcoin.node=btcd --btcd.rpcuser=kek --btcd.rpcpass=kek --debuglevel=trace --noencryptwallet