Skip to content

Instantly share code, notes, and snippets.

@fomigo
fomigo / how_to_use_hamcrest_matcher_with_phpunit.md
Created February 26, 2023 08:25 — forked from appkr/how_to_use_hamcrest_matcher_with_phpunit.md
How to use Hamcrest Matcher with PHPUnit

1 Set up

<?php // tests/HamcrestTestCase.php

namespace Tests;

use Hamcrest\MatcherAssert;
use Hamcrest\Util;
@fomigo
fomigo / .xbindkeysrc
Created August 12, 2021 05:11 — forked from MurzNN/.xbindkeysrc
Changing keyboard layout in Linux KDE + Electron apps via Alt+Shift workaround
# Add this to file in home folder
"~/bin/layout-switch.sh"
Alt + Shift_L
@fomigo
fomigo / path.md
Created September 10, 2020 15:06 — forked from nex3/path.md

The PATH is an important concept when working on the command line. It's a list of directories that tell your operating system where to look for programs, so that you can just write script instead of /home/me/bin/script or C:\Users\Me\bin\script. But different operating systems have different ways to add a new directory to it:

Windows

  1. The first step depends which version of Windows you're using:
  • If you're using Windows 8 or 10, press the Windows key, then search for and
@fomigo
fomigo / hello.vue
Created May 19, 2020 14:40 — forked from ryenski/hello.vue
Stimulus.js + Vue.js
<template>
<div id="app">
<p>{{ message }}</p>
</div>
</template>
<script>
export default {
data: function () {
return {
@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`