Skip to content

Instantly share code, notes, and snippets.

View Phil-Venter's full-sized avatar
💭
I honestly have no idea what I'm doing...

Caffeinated Coder Phil-Venter

💭
I honestly have no idea what I'm doing...
View GitHub Profile
@dreynaud
dreynaud / error-handling.md
Last active June 2, 2024 17:29
Error Handling in Practice

Error Handling in Practice

My experience is mostly with Java backend services in the cloud, so the advice in this post will almost certainly be biased towards this kind of error handling. But hopefully, some of it will be generally applicable and help you maintain and debug your programs in the long run.

I don't claim that these are universal best practices, but I have found these to be useful as general guidelines. As always, use your best judgment and do things that make sense in your context.

Log the whole thing

In Java, a full exception is:

@colxi
colxi / php-console.php
Created April 27, 2019 04:59
php-console.php
<?php
/*
Project Name: PHPConsole
Usage: Upload this file to FTP space, and run it from browser.
Description: PHPConsole is a simple and compact browser-based AJAX PHP console, that
allows direct acces to the PHP erver-side interpreter, recieving via AJAX all your
code output.
WARNING! ENSURE YOU CHANGE THE DEFAULT PASSWORD BEFORE UPLOADING!
Version: 1.5
Author: c0lx1
// Discord all events!
// A quick and dirty fleshing out of the discord.js event listeners (not tested at all!)
// listed here -> https://discord.js.org/#/docs/main/stable/class/Client
// Learn from this, do not just copy it mofo!
//
// Saved to -> https://gist.github.com/koad/316b265a91d933fd1b62dddfcc3ff584
// Last Updated -> Halloween 2022
/*
@marcus-at-localhost
marcus-at-localhost / debug.md
Created April 5, 2018 00:55
[Debug PHP] #php #debug

Find out where a function was called

function myFunc2Debug(){
	// output Linenumber and file where funcion was called.
	var_dump(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1));
}


myFunc2Debug();
@sagrawal31
sagrawal31 / formatSeconds.groovy
Created February 24, 2017 10:53
A simple Java/Groovy code to convert a given seconds value to hh:mm:ss format
import java.util.concurrent.TimeUnit
void convert(int secondsToConvert) {
long millis = secondsToConvert * 1000;
long hours = TimeUnit.MILLISECONDS.toHours(millis);
long minutes = TimeUnit.MILLISECONDS.toMinutes(millis) % TimeUnit.HOURS.toMinutes(1);
long seconds = TimeUnit.MILLISECONDS.toSeconds(millis) % TimeUnit.MINUTES.toSeconds(1);
String format = String.format("%02d:%02d:%02d", Math.abs(hours), Math.abs(minutes), Math.abs(seconds));
@gschema
gschema / intro.md
Last active November 27, 2023 04:35
Basic JavaScript MVC Implementation

Basic JavaScript MVC Implementation

Despite being derived from classical MVC pattern JavaScript and the environment it runs in makes Javascript MVC implementation have its own twists. Lets see how typical web MVC functions and then dive into simple, concrete JavaScript MVC implementation.

How Web MVC typically works

Typical server-side MVC implementation has one MVC stack layered behind the singe point of entry. This single point of entry means that all HTTP requests, e.g. http://www.example.com or http://www.example.com/whichever-page/ etc., are routed, by a server configuration, through one point or, to be bold, one file, e.g. index.php.

At that point, there would be an implementation of Front Controller pattern which analyzes HTTP request (URI at first place) and based on it decides which class (Controller) and its method (Action) are to be invoked as a response to the request (method is name for function and member is name for a variable when part of the class/object).

@dave1010
dave1010 / php-regex-router.php
Created September 13, 2011 15:46
php-regex-router.php
<?php
// dangerously simple PHP regular expression URL router
// requires a mod_rewrite like "RewriteRule . /index.php [L]"
function get($url, $callback) {
$matches = array();
if (preg_match('~' . $url . '~', $_SERVER['REQUEST_URI'], $matches)) {
echo call_user_func_array($callback, $matches);
die();
}