Skip to content

Instantly share code, notes, and snippets.

View Davenchy's full-sized avatar

Davenchy Davenchy

View GitHub Profile
@Davenchy
Davenchy / xcopy.bash
Created May 13, 2024 02:31
Copy/Paste bash scripts using xclip
#!/usr/bin/bash
# Simple bash script to copy files into clipboard using xclip
# Check if xclip is installed
if ! command -v xclip &> /dev/null; then
echo "Error: xclip is not installed. Please install xclip before running this script."
exit 1
fi
if [[ -z "$1" ]]; then
@Davenchy
Davenchy / user.php
Last active May 3, 2024 03:09
PHP User Model
class User {
private $id;
private $name;
private $email;
public function __construct(int $id, string $name, string $email) {
$this->id = $id;
$this->name = $name;
$this->email = $email;
}
@Davenchy
Davenchy / multer_example.js
Created May 1, 2024 11:08
Multer Example
const express = require('express');
const multer = require('multer');
const { v4: uuidv4 } = require('uuid');
const fs = require('fs');
const path = require('path');
const Resource = require('./models/Resource'); // Assuming you have a Resource model defined
const app = express();
// Set up multer storage configuration
@Davenchy
Davenchy / rclone-mount.bash
Created February 29, 2024 05:20
A bash script to mount a shared google drive directory into my disk using rclone
#!/usr/bin/env bash
# Use rclone to mount a shared google drive directory into my disk.
#
# Assumed you already created a readonly gdrive rclone config.
# Assumed you already added your access token or you authenticated the rclone config with your drive.
# Check the rclone docs for more info: https://rclone.org/drive/
# You don't have to assign everything, usually I leave everything empty and I use my browser to authenticate.
# the rclone config name
rclone_config_name="EmbeddedLinuxDiploma"
@Davenchy
Davenchy / README.md
Last active November 4, 2021 02:52
My zram control script

ZRam Controller Script

Install

The script uses zramctl under the hood

make sure to remove swap partition from /etc/fstab

Script

@Davenchy
Davenchy / event_emitter.dart
Last active November 8, 2021 22:23
Dart EventEmitter
import 'dart:async';
typedef EventHandler<E> = void Function(E event);
typedef HandlerCanceler = Future<void> Function();
class EventEmitter<T> {
final StreamController<T> _controller = StreamController.broadcast();
final List<StreamSubscription> _subscriptions = [];
final List<Completer> _completers = [];
@Davenchy
Davenchy / main.dart
Created November 1, 2021 12:02
Dart Middleware pattern
import 'middleware.dart';
void main(List<String> arguments) {
final password = MiddlewareManager<String, String>();
password.use((context, next, fail) {
if (context.isEmpty) fail('password is required');
next(context);
});
password.use((context, next, fail) {
if (context.length < 8) fail('password minimum 8 characters');
import 'package:flutter/material.dart';
class ConditionalBuilder extends StatelessWidget {
const ConditionalBuilder({
Key? key,
required this.condition,
required this.builder,
this.fallback,
}) : super(key: key);
@Davenchy
Davenchy / b_encode.dart
Last active December 20, 2020 22:47
BEncode class that encodes and decodes bencoded data
import 'dart:developer';
class BEncode {
static const int ssp = 58;
static const int esp = 101;
static const int isp = 105;
static const int dsp = 100;
static const int lsp = 108;
BEncode._();
import 'package:flutter/material.dart';
class CustomRangeSlider extends StatefulWidget {
final double width;
final double height;
final double markerWidth;
final double markerHeight;
final double sliderWidth;
final int divisions;
final double start;