Skip to content

Instantly share code, notes, and snippets.

View eldemcan's full-sized avatar

Can Eldem eldemcan

View GitHub Profile
@eldemcan
eldemcan / learning.exs
Created April 16, 2023 11:38
elixir study
?
learning
@eldemcan
eldemcan / http_net_chunk.rb
Created September 11, 2022 19:39
ruby http net with transfer-encoding chunked for supabase
# supabase returns transfer-encoding: chunked following snipped is used to convert payload into json
# you could adapt this to use any end point returning transfer-encoding: chunked
 
require 'net/http'
require 'json'
require 'stringio'
require 'zlipb'
uri = URI('')
req = Net::HTTP::Get.new(uri)
@eldemcan
eldemcan / systemd-cloudwatch-logs-tutorial.md
Created December 14, 2021 22:55 — forked from adam-hanna/systemd-cloudwatch-logs-tutorial.md
Forward systemd service logs to AWS Cloudwatch

Introduction

I often find myself ssh'ing into my servers and checking my systemd service logs with $ journalctl -f -u {name}.service. One day I got tired of this and wanted all of my important logs in once place (Amazon AWS Cloudwatch). To my dismay, there weren't any real good tutorials on how to do so. So, voilà.

Steps

Overall, it's a fairly simple process consisting of the following few steps.

1. Modify the service file

Open the service file with $ sudo vi /lib/systemd/system/{name}.service

Modify the [Service] section:

@eldemcan
eldemcan / shell-execution.rb
Created December 5, 2020 14:47 — forked from JosephPecoraro/shell-execution.rb
Shell Execution in Ruby
# Ways to execute a shell script in Ruby
# Example Script - Joseph Pecoraro
cmd = "echo 'hi'" # Sample string that can be used
# 1. Kernel#` - commonly called backticks - `cmd`
# This is like many other languages, including bash, PHP, and Perl
# Synchronous (blocking)
# Returns the output of the shell command
# Docs: http://ruby-doc.org/core/classes/Kernel.html#M001111
@eldemcan
eldemcan / error.txt
Last active June 12, 2020 20:39
async-http
9.32s debug: Async::Pool::Controller [oid=0x3ff4114e9248] [pid=70267] [2020-06-11 21:41:38 +0100]
| Reuse #<Async::HTTP::Protocol::HTTP2::Client 10 active streams>
9.32s debug: Async::Pool::Controller [oid=0x3ff4114e9248] [pid=70267] [2020-06-11 21:41:38 +0100]
| Reuse #<Async::HTTP::Protocol::HTTP2::Client 10 active streams>
9.32s debug: Async::Pool::Controller [oid=0x3ff4114e9248] [pid=70267] [2020-06-11 21:41:38 +0100]
| Reuse #<Async::HTTP::Protocol::HTTP2::Client 9 active streams>
9.32s debug: Async::Pool::Controller [oid=0x3ff4114e9248] [pid=70267] [2020-06-11 21:41:38 +0100]
| Reuse #<Async::HTTP::Protocol::HTTP2::Client 8 active streams>
9.33s debug: Async::Pool::Controller [oid=0x3ff4114e9248] [pid=70267] [2020-06-11 21:41:38 +0100]
| Reuse #<Async::HTTP::Protocol::HTTP2::Client 7 active streams>
@eldemcan
eldemcan / main.rb
Last active May 15, 2020 15:01
ruby async gem benchmarking
# Calculating -------------------------------------
# sync 1.000 i/100ms
# async 1.000 i/100ms
# -------------------------------------------------
# sync 0.395 (± 0.0%) i/s - 2.000
# async 0.335 (± 0.0%) i/s - 2.000 in 5.969521s
# Comparison:
# sync: 0.4 i/s
# async: 0.3 i/s - 1.18x slower
@eldemcan
eldemcan / runlength.ex
Created June 8, 2017 19:45
Run length encoding is a compression algorithm that takes runs of sequential items in a series of data points, replacing that run with a single instance of the data point and the number of elements in that run.
defmodule Runlength do
def encode(string) do
case string do
<<head :: binary-size(1), rest :: binary >> ->
list_string = String.codepoints(string)
same_character_string_length = Enum.count(Enum.take_while(list_string,fn(char) -> char == head end))
Integer.to_string(same_character_string_length) <> head <> Runlength.encode(List.to_string(Enum.drop(list_string, same_character_string_length)))
"" ->
""
end
@eldemcan
eldemcan / monad.swift
Created February 19, 2017 20:23
monad example in swift trying to understand the concept
enum Maybe<T> {
case some(T)
case none
}
enum Maybe<T> {
case some(T)
case none
}
defmodule ExampleApp do
def myMulti(chunks) do
t= Enum.map_reduce(chunks,1,fn(x,acc)-> {x, x* acc} end)
elem(t,1)
end
def main() do
string = "73167176531330624919225119674426574742355349194934969835203127745063262395783180169848018694788518438586156078911294949545950173795833195285320880551112540698747158523863050715693290963295227443043557668966489504452445231617318564030987111217223831136222989342338030813533627661428280644448664523874930358907296290491560440772390713810515859307960866701724271218839987979087922749219016997208880937766572733300105336788122023542180975125454059475224352584907711670556013604839586446706324415722155397536978179778461740649551492908625693219784686224828397224137565705605749026140797296865241453510047482166370484403199890008895243450658541227588666881164271714799244429282308634656748139191231628245861786645835912456652947654568284891288314260769004224219022671055626321111109370544217506941658960408071984038509624554443629812309878799272442849091888458015616609
@eldemcan
eldemcan / experiment.rb
Created November 28, 2016 15:07
Some interesting ruby code for beginners
module MyModule
def self.included(base)
@classes ||= []
@classes << base.name
end
def self.classes
@classes
end
end