Skip to content

Instantly share code, notes, and snippets.

@fomigo
fomigo / java-exception-handling-best-practices.md
Created April 28, 2020 05:16 — forked from raineorshine/java-exception-handling-best-practices.md
5 Great Resources for Exception Handling Best Practices in Java

General Tip

"The trick is to catch exceptions at the proper layer, where your program can either meaningfully recover from the exception and continue without causing further errors, or provide the user with specific information, including instructions on how to recover from the error. When it is not practical for a method to do either of these, simply let the exception go so it can be caught later on and handled at the appropriate level."

Resources

Advantages of Exceptions
Excellent example of separating error-handling code from program logic

Three Rules for Effective Exception Handling
Longer explanation and case study of exception use, including the basic principles of "throw early" and "catch late". Clear and thorough.

@fomigo
fomigo / ManacalaWell.rb
Created November 25, 2019 16:15 — forked from thutch/ManacalaWell.rb
Mancala Object-Oriented Recursion example
class Well
attr_accessor :next_well, :seeds, :owner
def initialize anOwner
self.seeds = 0
self.owner = anOwner
end
def sow
current_seeds = self.seeds
SELECT p.id, name, LENGTH(body) AS len
FROM (
SELECT id
FROM projects
ORDER BY id
LIMIT 150000, 10
) o
JOIN projects p
ON p.id = o.id
ORDER BY p.id
@fomigo
fomigo / .gitconfig
Created October 31, 2019 07:35 — forked from johnpolacek/.gitconfig
My current .gitconfig aliases
[alias]
co = checkout
cob = checkout -b
coo = !git fetch && git checkout
br = branch
brd = branch -d
brD = branch -D
merged = branch --merged
st = status
aa = add -A .
<?php
function resizeImage($source, $dest, $new_width, $new_height, $quality)
{
// Taken from http://salman-w.blogspot.com/2009/04/crop-to-fit-image-using-aspphp.html
$image = new Phalcon\Image\Adapter\GD($source);
$source_height = $image->getHeight();
$source_width = $image->getWidth();
$source_aspect_ratio = $source_width / $source_height;
$desired_aspect_ratio = $new_width / $new_height;
if ($source_aspect_ratio > $desired_aspect_ratio) {
@fomigo
fomigo / README.md
Created October 13, 2019 07:09 — forked from Ocramius/README.md
`__invoke` vs `function` vs `Closure`
@fomigo
fomigo / Antonyms.md
Created August 20, 2019 06:53 — forked from maxtruxa/Antonyms.md
A list of common terms used in programming and their respective antonyms.

Antonym List

Note: The table headings (positive/negative) are not necessarily meaningful.

Positive Negative
acquire release
add remove (e.g. an item), subtract (arithmetic)
advance retreat
allocate deallocate (correct), free (common)
allow deny
@fomigo
fomigo / defaultTemplateByParentTv.plugin.php
Created April 9, 2012 15:37 — forked from bfncs/defaultTemplateByParentTv.plugin.php
Default Children Template by Parent TV - modX Revolution Plugin
<?php
/**
* =========================
* defaultTemplateByParentTv
* =========================
*
* Plugin for modX Revolution
* Set default template for children of a ressource
*
* Author:
@fomigo
fomigo / LangRouter.php
Created October 30, 2012 16:18 — forked from gadamiak/LangRouter.php
Language context router for use with Babel extra for MODX Revolution
<?php
/* LangRouter
* ==========
*
* This plugin is meant to be used with Babel extra for MODX Revolution. It
* takes care of switching contexts, which hold translations, depending on URL
* requested by client. LangRouter works with so called subfolder based setup,
* in which many languages are served under a single domain but are
* differentiated by a virtual subfolder indicating the language, eg.
* mydomain.com/pl/.
@fomigo
fomigo / gist:5559983
Last active May 15, 2016 01:02
просмотренные страницы
<?php
$id = $modx->resource->id;
$tpls = explode(',', $modx->getOption('minishop.goods_tpl'));
if (!isset($limit)) {$limit = 10;}
if (!isset($tpl)) {$tpl = 'tpl.msGoods.row';}
// Вносим ID просмотренных товаров
if (in_array($modx->resource->template, $tpls)) {
if (!isset($_SESSION['viewed'])) {