Skip to content

Instantly share code, notes, and snippets.

Avatar
💡

Alan Boglioli aboglioli

💡
View GitHub Profile
@aboglioli
aboglioli / repo_save_method.go
Last active May 24, 2021
Repository with items and save method replacing existing values
View repo_save_method.go
package main
import (
"fmt"
"encoding/json"
)
type ID struct {
ID string
}
@aboglioli
aboglioli / scammer_flood.js
Created May 20, 2021
Scammer website flood using proxy list
View scammer_flood.js
const axios = require('axios');
const HttpsProxyAgent = require('https-proxy-agent');
const cheerio = require('cheerio');
const getProxies = async () => {
const res = await axios.get('PROXY LIST');
const $ = cheerio.load(res.data);
const elements = $(
'body > div.wrap > div.services_proxylist.services > div > div.table_block > table > tbody > tr',
).toArray();
View scrape_site_for_recaptcha.js
const puppeteer = require('puppeteer');
const proxy = ''; // '161.35.58.75:8080';
const url = '';
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
const scrape = async (browser, prefix) => {
const page = await browser.newPage();
console.log(`Visiting ${url}`);
@aboglioli
aboglioli / ts-class-deserialize.ts
Last active Jan 6, 2021
Typescript class deserialization (using JSON.parse() and public properties)
View ts-class-deserialize.ts
const json = `{
"type": "two",
"value": 25.5,
"items": [{
"order": 2,
"value": "hello"
}, {
"order": 5,
"value": "bye"
}]
@aboglioli
aboglioli / async_trait_send_sync_markers.rs
Last active Jul 29, 2020
Trait object with async methods (thanks to async-trait) with Send and Sync markers
View async_trait_send_sync_markers.rs
use std::sync::Arc;
use async_trait::async_trait; // 0.1.36
#[async_trait]
trait Repo {
async fn find(&self) -> i32;
}
struct RepoImpl;
View basic_event_bus.rs
use std::cell::{Cell, RefCell};
use std::collections::HashMap;
use std::fmt::Debug;
use std::rc::Rc;
#[derive(Debug)]
pub struct Error;
pub trait Event: Debug {
fn code(&self) -> &str;
@aboglioli
aboglioli / callback_executor.rs
Created Jul 26, 2020
Simple example of using an array of FnMut to execute inner code inside a trait object.
View callback_executor.rs
pub trait Executor {
fn run(&mut self, f: &mut dyn FnMut(i32) -> i32);
}
struct SimpleExecutor {
v: i32,
}
impl Executor for SimpleExecutor {
fn run(&mut self, f: &mut dyn FnMut(i32) -> i32) {
@aboglioli
aboglioli / static_and_dynamic_dispatch_for_shared_dependencies.rs
Created Jul 19, 2020
Static and dynamic dispatch (trait objects, when needed) for shared dependencies with Rc and RefCell.
View static_and_dynamic_dispatch_for_shared_dependencies.rs
use std::rc::Rc;
use std::cell::RefCell;
// Databases
trait DB {
fn find(&self) -> String;
}
struct SQL;
@aboglioli
aboglioli / refcell_rc_dyn.rs
Created Jul 17, 2020
Change implementation of trait object using RefCell<Rc<dyn Obj>>
View refcell_rc_dyn.rs
use std::rc::Rc;
use std::cell::RefCell;
// Databases
trait DB {
fn find(&self) -> String;
}
struct SQL;
@aboglioli
aboglioli / generic_to_trait_object.rs
Last active May 9, 2020
Generic to trait object and boxing (Box<T>) inside method.
View generic_to_trait_object.rs
use std::fmt::Debug;
trait Handler: Drop + Debug {
fn handle(&self, data: &Data);
}
#[derive(Debug)]
struct Processor(String);
impl Handler for Processor {
fn handle(&self, data: &Data) {