Skip to content

Instantly share code, notes, and snippets.

View Valian's full-sized avatar
🔮
Diving deep into Elixir

Jakub Skałecki Valian

🔮
Diving deep into Elixir
View GitHub Profile
@Valian
Valian / script.js
Last active November 30, 2016 12:54
Simple script to find all server IPs from OVH panel site and print ready to use Docker Swarm inventory file
function get_ansible_config(managersCount, managersStartNr, workersStartNr) {
var createAnsibleString = function(name, startNumber){
return function(a, i) {
return name + (i + 1 + (startNumber || 0)) + ' ansible_ssh_host=' + a + ' ansible_ssh_user=ubuntu';
}
};
var addresses = $x('//*[@data-ng-if="ip.ip"]/text()')
.filter(function(a){return a.wholeText.trim() != ""})
.map(function(a) {return a.wholeText.trim()});
var str = "";
@Valian
Valian / Dockerfile
Last active February 26, 2019 06:06
Fast way to fix not working ctype.util.find_library() in python alpine. Rather quick workaround, but works :)
FROM python:2-alpine
ENV PYTHONUNBUFFERED=1 \
PROJECT_ROOT=/srv
COPY requirements.txt $PROJECT_ROOT/
RUN apk add --update --virtual build-dependencies build-base python-dev \
&& cd $PROJECT_ROOT && pip install -r requirements.txt \
@Valian
Valian / example_forms.py
Last active February 8, 2021 14:32
Django MultipleFormMixin for displaying dynamic number of forms on the same page. Compatible with the standard FormMixin.
class ContactForm(forms.Form):
name = forms.CharField(max_length=60)
message = forms.CharField(max_length=200, widget=forms.TextInput)
class SubscriptionForm(forms.Form):
email = forms.EmailField()
want_spam = forms.BooleanField(required=False)
@Valian
Valian / profile_middleware.py
Created May 6, 2017 14:13
Detailed Hotshot profiler middleware for Django
# Orignal version taken from http://www.djangosnippets.org/snippets/186/
# Original author: udfalkso
# Modified by: Shwagroo Team and Gun.io
# Further modified by: Jakub Skalecki (https://rock-it.pl)
import hotshot
import hotshot.stats
import textwrap
import os
@Valian
Valian / Dockerfile
Created August 26, 2017 11:39
Simple Dockerfile to run openjdk application
FROM openjdk:8
ENV JAVA_OPTS=""
WORKDIR /srv
COPY snapshot.jar .
CMD ["java $JAVA_OPTS -jar snapshot.jar"]
@Valian
Valian / arbitrage.py
Created January 18, 2018 23:33
Short script for finding Binance Triangle arbitrage opportunities - requires python-binance installed
from collections import defaultdict
from operator import itemgetter
from time import time
from binance.client import Client
FEE = 0.0005
PRIMARY = ['ETH', 'USDT', 'BTC', 'BNB']
@Valian
Valian / run.sh
Last active July 3, 2018 11:02
Ubuntu Google Cloud Platform server - mount new disk, install docker and docker compose and change docker disk to new location. CAUTION: Only tested on a fresh server!!
#!/bin/bash
set -e
DISK="$1"
MOUNTPOINT="$2"
if [ -z "$DISK" ] || [ -z "$MOUNTPOINT" ]; then
echo "Usage: run.sh DISK MOUNTPOINT"
exit 1
@Valian
Valian / sequential_execution.py
Created July 21, 2021 11:34
Python decorator and manager replacing recursive execution into sequential. Sometimes useful - my use case was with nested Django Rest Framework serializers, where updates had to happen in "layers".
from contextlib import contextmanager
from contextvars import ContextVar
from functools import wraps, partial
_sequential_execution_active = ContextVar('bulk_update_active', False)
_sequential_execution_callbacks = ContextVar('bulk_update_callbacks', None)
@contextmanager
@Valian
Valian / m1_docker.bash
Created March 13, 2024 10:34
First one running on M1 inside docker (failing), another one not (working)
docker run --rm -it elixir:1.16 mix run --no-mix-exs -e 'Mix.install(dockerexec: "~> 2.0")'
* creating /root/.mix/archives/hex-2.0.6
Resolving Hex dependencies...
Resolution completed in 0.01s
New:
dockerexec 2.0.3
* Getting dockerexec (Hex package)
* creating /root/.mix/elixir/1-16/rebar3
===> Fetching rebar3_hex v7.0.7
@Valian
Valian / app.html.heex
Created May 2, 2024 17:34
Phoenix LiveView teleport hook
<.flash_group flash={@flash} />
<main>
<%= @inner_content %>
</main>
<%!-- We're doing teleport because navigation is rendered in root layout which is not updated --%>
<%!-- Notice "hidden" class, it's important because we're not really teleporting content, but duplicating it --%>
<div :if={@current_user} id="onboarding-render" phx-hook="teleport" data-teleport-target="onboarding" class="hidden">
<MyApp.Onboarding.onboarding current_user={@current_user} />