Skip to content

Instantly share code, notes, and snippets.

@jibiel
jibiel / mock_package_info.dart
Last active July 3, 2021 23:02
[Flutter] How to mock/stub PackageInfo after MethodChannel#setMockMethodCallHandler deprecation
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
void mockPackageInfo() {
const channel = MethodChannel('plugins.flutter.io/package_info');
handler(MethodCall methodCall) async {
if (methodCall.method == 'getAll') {
return <String, dynamic>{
'appName': 'myapp',
@jibiel
jibiel / assets.dart
Created April 3, 2021 03:48
Dark Mode-aware asset images in Flutter
/// lib/utilities/assets.dart
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
/// Usage:
///
/// The image file is located at lib/assets/images/path/to/image.png.
///
/// 1. Image has no dark mode variant.
@jibiel
jibiel / friendship.rb
Last active October 19, 2023 13:44
DRY Mutual Friendships / Friends in Ruby on Rails
# app/models/friendship.rb
class Friendship < ApplicationRecord
belongs_to :user
belongs_to :friend, class_name: 'User'
end
@jibiel
jibiel / fonts.sh
Created October 9, 2019 10:53
Make macOS Catalina font rendering and smoothing slightly more bearable
defaults write -g CGFontRenderingFontSmoothingDisabled -bool false
defaults -currentHost write -g AppleFontSmoothing -int 3
require 'active_support/concern'
require 'active_support/callbacks'
module ActiveSupport
module Testing
module SetupAndTeardown
module ForClassicTestUnit
# This redefinition is unfortunate but test/unit shows us no alternative.
# Doubly unfortunate: hax to support Mocha's hax.
def run(result)
@jibiel
jibiel / google_analytics_including_today.user.js
Created September 28, 2012 08:47
Include today in Google Analytics' default date range (updated for 2012)
// ==UserScript==
// @name Google Analytics - Include Today
// @author Storm Consultancy & jibiel
// @description Include today in Google Analytics' default date range
// @include https://www.google.com/analytics/web/*
// @version 1.1
// ==/UserScript==
// Function to add days to a date, use negative number to subtract
function addDays(myDate,days) {
@jibiel
jibiel / cherry-pick.sh
Created January 24, 2012 06:41
Submitting github pull request for only latest/certain commit
# Taken from http://stackoverflow.com/questions/5256021/submitting-github-pull-request-for-only-latest-commit
git remote add upstream git://github.com/rsl/stringex
git fetch upstream
git checkout -b upstream upstream/master
git cherry-pick *sha1*
git push origin upstream
# Then you'll see your upstream branch on github, switch to it and submit the pull request with just the changes you want.
@jibiel
jibiel / routes.rb
Created January 17, 2012 13:09
Standard Rails 3 Routing Guidelines
# The priority is based upon order of creation:
# first created -> highest priority.
# Sample of regular route:
match 'products/:id' => 'catalog#view'
# Keep in mind you can assign values other than :controller and :action
# Sample of named route:
match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
# This route can be invoked with purchase_url(:id => product.id)