Skip to content

Instantly share code, notes, and snippets.

View aboglioli's full-sized avatar
💡

Alan Boglioli aboglioli

💡
View GitHub Profile
@aboglioli
aboglioli / repo_save_method.go
Last active May 24, 2021 19:19
Repository with items and save method replacing existing values
package main
import (
"fmt"
"encoding/json"
)
type ID struct {
ID string
}
@aboglioli
aboglioli / scammer_flood.js
Created May 20, 2021 06:36
Scammer website flood using proxy list
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();
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 January 6, 2021 23:16
Typescript class deserialization (using JSON.parse() and public properties)
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 July 29, 2020 06:41
Trait object with async methods (thanks to async-trait) with Send and Sync markers
use std::sync::Arc;
use async_trait::async_trait; // 0.1.36
#[async_trait]
trait Repo {
async fn find(&self) -> i32;
}
struct RepoImpl;
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 July 26, 2020 23:30
Simple example of using an array of FnMut to execute inner code inside a trait object.
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 July 19, 2020 23:05
Static and dynamic dispatch (trait objects, when needed) for shared dependencies with Rc and RefCell.
use std::rc::Rc;
use std::cell::RefCell;
// Databases
trait DB {
fn find(&self) -> String;
}
struct SQL;
@aboglioli
aboglioli / refcell_rc_dyn.rs
Created July 17, 2020 09:55
Change implementation of trait object using RefCell<Rc<dyn Obj>>
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 21:04
Generic to trait object and boxing (Box<T>) inside method.
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) {