Skip to content

Instantly share code, notes, and snippets.

View kerolloz's full-sized avatar

Kerollos Magdy kerolloz

View GitHub Profile
import axios, { AxiosError } from 'axios';
import fs from 'fs';
import formData from 'form-data';
const imageUploaderKeyEnvVar = process.env['IMG_UPLOADER_KEY'];
export class ImageUploader {
static async upload(imagePath: string): Promise<string> {
const form = new formData();
const image = fs.readFileSync(imagePath, { encoding: 'base64' }).toString();
@kerolloz
kerolloz / active_record_enum.rb
Last active April 23, 2021 22:05
ActiveRecord::Enum article on Medium
def assert_valid_value(value)
unless value.blank? || mapping.has_key?(value) || mapping.has_value?(value)
raise ArgumentError, "'#{value}' is not a valid #{name}"
end
end
@kerolloz
kerolloz / remove-keys.js
Created April 7, 2021 18:27
Remove all keys in Redis
require("dotenv").config();
const redis = require("redis");
const { REDIS_URL } = process.env;
(async () => {
// connect to Redis
let redisClient;
if (REDIS_URL) {
redisClient = redis.createClient(REDIS_URL);
const Sequelize = require("sequelize");
module.exports = new Sequelize({
database: "test",
username: "root",
password: "mysecretpassword",
dialect: "postgres",
});
@kerolloz
kerolloz / main.go
Created June 23, 2020 23:33
rotate images in current directory
package main
import (
"fmt"
"io/ioutil"
"log"
"regexp"
"github.com/disintegration/imaging"
)
#include <iostream>
#include "exercise.hpp"
#define endl '\n'
using namespace std;
int print_usage()
{
cout << "./create-exercise " << endl;
cout << "./create-exercise [exercise_number]'" << endl;
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int answer = n; /// assume we used all of coin1
for (int c4 = 0; c4 <= n / 4; c4++) { // try to take c4 of coin4
for (int c3 = 0; c3 <= (n - 4 * c4) / 3; c3++) { // try to take c3 of coin3
int c1 = n - (4 * c4 + 3 * c3);
#include <stdio.h>
int main () {
long long n, m;
scanf("%lld %lld", &n, &m);
const long long MOD = 17e7; // same as 17x10^7
long long ans = m;
// or ans = 1 and for(int i = 0; i < n; i++)
@kerolloz
kerolloz / parsePosts.js
Last active December 10, 2019 18:02
This script parses posts in a Facebook group
function get_all_posts_content() {
let my_txt = "";
const posts = document.querySelectorAll("._5pbx.userContent");
for (const post of posts) {
my_txt += post.innerText + "\n-------------------\n"
}
return my_txt
}
function click_all_see_more() {
@kerolloz
kerolloz / vscode-install.sh
Created November 7, 2019 20:38
Install VSCode for debian based linux distros
sudo apt update
sudo apt install software-properties-common apt-transport-https wget
wget -q https://packages.microsoft.com/keys/microsoft.asc -O- | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main"
sudo apt update
sudo apt install code