Skip to content

Instantly share code, notes, and snippets.

@mbeltagy
mbeltagy / ComfyUIAnimated.sh
Last active January 22, 2024 22:01
ComfyUI with selected Models and AnimateDiff models and node
#!/bin/false
# This file will be sourced in init.sh
# https://raw.githubusercontent.com/ai-dock/comfyui/main/config/provisioning/animated.sh
printf "\n##############################################\n# #\n# Provisioning container #\n# #\n# This will take some time #\n# #\n# Your container will be ready on completion #\n# #\n##############################################\n\n"
## Set paths
## main paths
@mbeltagy
mbeltagy / blog_julia_wordle_repl_session1.jl
Last active January 29, 2022 09:59
Wordle in Julia gist for use in my blogs
julia> let_in_pos = Dict{Int,Char}();
julia> let_not_in_pos = Dict{Char,Vector{Int}}();
julia> let_not_in_word = Set{Char}();
julia> word_set = copy(words);
julia> word=rand(word_set)
"excel"
julia> update_constraints_by_response!(word, "00020", let_in_pos, let_not_in_pos, let_not_in_word)
julia> word_set_reduction!(word_set, let_in_pos, let_not_in_pos, let_not_in_word)
698-element Vector{String}:
@mbeltagy
mbeltagy / aco20.jl
Created December 20, 2021 20:28
AoC 20 Trench Map
lines = readlines("input20.txt")
algo = lines[1]|> x->[c=='.' ? false : true for c in x]
imag = lines[3:end] .|> (x->[c=='.' ? false : true for c in x]) |> x->hcat(x...)
# pad the image by zeroes to simulate the infnitued
function pad(imag,pad)
oldsize = size(imag)
newsize = oldsize .+ 2*pad
new_imag = zeros(eltype(imag), newsize...)
new_imag[pad+1:oldsize[1]+pad,pad+1:oldsize[2]+pad] .= imag
@mbeltagy
mbeltagy / convet_images.jl
Created November 30, 2021 12:26
Using Julia and ImageMagick to convert an directory of images from png to jpg
input_dir = "images_need_fix/"
output_dir = "images_fixed/"
input_files = readdir(input_dir)
filter!(x->endswith(x,"png"),input_files)
for f in input_files
input_base_name = splitext(f)[1]
output_file_name = input_base_name*".jpg"
from = joinpath(input_dir,f)
@mbeltagy
mbeltagy / pascal.jl
Created November 9, 2019 21:05
Pascal Triangle calculation
"Pascal triangle"
function pascal(n)
(n<=0) && error("Pascal trinalge can not have zero or negative rows")
r=Vector{Int}(undef,n)
pr=Vector{Int}(undef,n)
pr[1]=r[1]=1
println(@view pr[1])
for i=2:n
r[1]=r[i]=1
for j=2:i-1
@mbeltagy
mbeltagy / roundupdown.jl
Created June 1, 2019 08:57
Julia rounding up or down to the nearest integer mulitple
round_up(x,m::Integer)=ceil(Int,x/m).*m
round_down(x,m::Integer)=floor(Int,x/m).*m
@mbeltagy
mbeltagy / Interpolation_example.jl
Last active February 14, 2019 18:03
Interpolations Example
using Interpolations, Plots
# Demonstrating interpolations
x=0:0.5:2π
y=sin.(x);
itp=LinearInterpolation(x,y);
y2=[itp(x) for x in 0:0.1:2];
x2=0:0.1:6;
y2=[itp(x) for x in x2];
itpC=CubicSplineInterpolation(x,y);
@mbeltagy
mbeltagy / Buildingread.jl
Created February 10, 2019 20:46
Building Expenses Filtration
using CSV
data=CSV.read("Jan19.csv")
# The occursin is used to get the line where the transfer happened...hence summing all transfers
audi_ind=findall(x->ismissing(x) ? false : occursin(r"audi"i,x), data[:,1])
data[audi_ind,1:3][:Cash] |> x-> prod.(split.(x,',')) |> x-> Meta.parse.(x) |> sum
@mbeltagy
mbeltagy / extractcerts.jl
Last active November 26, 2017 21:33
Getting TensorFlow.jl to build properly
#=
I was getting the following errors when running
Pkg.update("TensorFlow")
On my ubunutu 14.04
INFO: Building TensorFlow.jl for CPU use only. To enable the GPU, set the TF_USE_GPU environment variable to 1 and rebuild TensorFlow.jl
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
curl: (60) server certificate verification failed. CAfile: /etc/ssl/certs/ca-certificates.crt CRLfile: none
@mbeltagy
mbeltagy / readFusionTable.jl
Created July 15, 2017 01:24
Opening up fusion table from Julia
# Reading a fusion table from Julia
using Requests, DataFrames
request_url = "https://www.googleapis.com/fusiontables/v2/query"
query = "SELECT * FROM 1KlX4PFF81wlx_TJ4zGudN_NoV_gq_GwrxuVau_M"
resp=get(request_url,query=Dict("sql"=>query, "key"=>"somekey","alt"=>"csv"))
myTable=readtable(IOBuffer(resp.data));