Skip to content

Instantly share code, notes, and snippets.

View ivanzotov's full-sized avatar
🌼
thriving

Ivan Zotov ivanzotov

🌼
thriving
View GitHub Profile
@kachar
kachar / Link-Next13.tsx
Last active May 6, 2024 21:38
Next.js Link + Material UI Link/Button components bundled with forwardRef
@stephanecopin
stephanecopin / Publishers+CombineLatestMany.swift
Created February 13, 2020 00:58
An implemention of `CombineLatestMany` for Combine (Swift), which takes takes an array of `Publisher` and return a collection of values, based on their latest value.
import Combine
private protocol LockImplementation {
mutating func lock()
mutating func `try`() -> Bool
mutating func unlock()
}
private struct UnfairLock: LockImplementation {
private var unfairLock = os_unfair_lock_s()
@scmx
scmx / extract-objects-from-rails-models-and-controllers.md
Last active February 17, 2023 11:28
7 Patterns to Refactor Rails Models 7 years later #rails #model #refactor #valueobject #serviceobject #formobject #queryobject #viewobject #policyobject #decorator

7 Patterns to Refactor Rails Models 7 years later

You may have read the following excellent blogpost by Brian Helmkamp of CodeClimate. It nicely describes 7 types of objects that can be extracted from models and controllers in a Rails-app.

7 Patterns to Refactor Fat ActiveRecord Models https://codeclimate.com/blog/7-ways-to-decompose-fat-activerecord-models/ Brian Helmkamp on Oct 17, 2012.

Here are my thoughts on it, reading it as an experienced rails developer, 7 years later 😅 👴

@kentcdodds
kentcdodds / 0. README.md
Last active February 15, 2023 14:19
coverage information for https://testingjavascript.com

Code Coverage

Code coverage is accomplished with Jest thanks to babel-plugin-istanbul. It transforms your code to "instrument" it for coverage. When your tests are finished, Jest reads the coverage data to generate the coverage report.

Reviewing code that has been instrumented for coverage can help understanding how coverage works and how to interpret coverage reports.

@shaps80
shaps80 / AVPlayer+Scrubbing.swift
Last active June 12, 2024 00:09
Enables smooth frame-by-frame scrubbing (in both directions) – similar to Apple's applications.
public enum Direction {
case forward
case backward
}
internal var player: AVPlayer?
private var isSeekInProgress = false
private var chaseTime = kCMTimeZero
private var preferredFrameRate: Float = 23.98
@deinspanjer
deinspanjer / verify_google_jwt.sql
Created October 6, 2016 00:34
A PostgreSQL function using the plv8 language that can validate a JWT token from Google Sign-In
CREATE EXTENSION plv8;
CREATE OR REPLACE FUNCTION verify_google_jwt(jwt_token TEXT)
RETURNS JSONB
LANGUAGE plv8 IMMUTABLE STRICT
AS $$
function logerror(msg) {
plv8.elog(ERROR, msg);
}
@ChuckJHardy
ChuckJHardy / example_activejob.rb
Last active June 28, 2024 12:52
Example ActiveJob with RSpec Tests
class MyJob < ActiveJob::Base
queue_as :urgent
rescue_from(NoResultsError) do
retry_job wait: 5.minutes, queue: :default
end
def perform(*args)
MyService.call(*args)
end
@powellc
powellc / pg_backup_all.sh
Last active October 1, 2023 19:14
Bash script to backup all postgresql databases on a server, run with cron once a day or 5 times a day, whatever. Just updated it so it ignores your postgres db, and also bzips the backups and adds a symlink to a latest directory. Sweet.
#!/bin/bash
# Location to place backups.
backup_dir="/var/backups/databases/"
nightly_dir="/var/backups/databases/latest/"
#String to append to the name of the backup files
backup_date=`date +%d-%m-%Y`
#Numbers of days you want to keep copie of your databases
number_of_days=15
databases=`psql -l -t | cut -d'|' -f1 | sed -e 's/ //g' -e '/^$/d'`
for i in $databases; do if [ "$i" != "postgres" ] && [ "$i" != "template0" ] && [ "$i" != "template1" ] && [ "$i" != "template_postgis" ]; then
@paulirish
paulirish / rAF.js
Last active July 2, 2024 11:59
requestAnimationFrame polyfill
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel
// MIT license
(function() {
var lastTime = 0;
var vendors = ['ms', 'moz', 'webkit', 'o'];
class AdminController < ApplicationController
before_filter do |controller|
controller.redirect_to login_path unless logged_in?
end
end