Skip to content

Instantly share code, notes, and snippets.

View thisismydesign's full-sized avatar

Csaba Apagyi thisismydesign

View GitHub Profile
@thisismydesign
thisismydesign / seeds.rb
Last active January 26, 2019 17:23
Ruby: When and how to use factories for seeding? /1
seed_file = Rails.root.join('db', 'seeds', "#{Rails.env}.rb")
load seed_file if File.file?(seed_file)
@thisismydesign
thisismydesign / xyz_service_spec.rb
Last active September 2, 2021 22:05
Ruby: Use factories for your webmocks /2
stub_request(:get, %r{#{ENV['XYZ_SERVICE_SERVER']}/api/v2/get_entities*})
.to_return(build(:xyz_service_get_entities_response))
allow(XyzService).to receive(:get_entities).and_return(build(:xyz_service_get_entities_response))
@thisismydesign
thisismydesign / xyz_service_get_entities_responses.rb
Last active September 2, 2021 21:44
Ruby: Use factories for your webmocks /1
FactoryBot.define do
factory :xyz_service_get_entities_response, class: Hash do
skip_create
initialize_with { { body: attributes[:body].to_json }.stringify_keys }
body do
{
data: [
{ key: SecureRandom.hex, name: Faker::Lorem.word },
{ key: SecureRandom.hex, name: Faker::Lorem.word }
@thisismydesign
thisismydesign / leveling-like-a-coward.rb
Last active November 4, 2018 21:47
AFK leveling in PoE in The Coward's Trial map with Ruby
require 'file-tail'
require 'rb-notifu'
File.open("C:/Program Files (x86)/Grinding Gear Games/Path of Exile/logs/Client.txt") do |log|
log.extend(File::Tail)
log.backward(1).tail do |line|
Notifu::show :message => "NEXT ROOM", :type => :warn, :time => 5 do; end if line=~/The room grows still and quiet/
Notifu::show :message => "DONE", :type => :warn, :time => 5 do; end if line=~/The oppressive atmosphere slowly dissipates/
Notifu::show :message => "SOMEONE LEFT", :type => :warn, :time => 5 do; end if line=~/has left the area/
@thisismydesign
thisismydesign / jest-example-snapshot-config.js
Last active November 3, 2018 20:14
No more __snapshots__ folders with Jest! - example configuration
// config/snapshotResolver.js
module.exports = {
resolveSnapshotPath: (testPath, snapshotExtension) => testPath + snapshotExtension,
resolveTestPath: (snapshotFilePath, snapshotExtension) => snapshotFilePath.slice(0, -snapshotExtension.length),
};
// package.json
"jest": {
"snapshotResolver": "<rootDir>/config/snapshotResolver.js"
}
@thisismydesign
thisismydesign / merge.ps1
Created October 19, 2018 09:46
Merge videos with VLC
cd FOLDER
."C:\Program Files\VideoLan\VLC\vlc.exe" input1.mp4 input2.mp4 vlc://quit --sout "#gather:std{access=file,dst=output.avi}" --sout-keep
package com.thisismydesign;
import org.apache.commons.codec.binary.Hex;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public final class EscapeUtil {
private final static Pattern pipe = Pattern.compile("\\|");
@thisismydesign
thisismydesign / solution_and_use_case.rb
Created August 21, 2018 12:46
Ruby: how to use self.included meaningfully, solution and use case
module CreateClassMethodsUponInclude
def self.included(base)
base.define_singleton_method :included do |base|
base.extend(self)
end
end
end
module MyModule
include CreateClassMethodsUponInclude
@thisismydesign
thisismydesign / solution.rb
Created August 21, 2018 12:44
Ruby: how to use self.included meaningfully, solution
module CreateClassMethodsUponInclude
def self.included(base)
# does what we want
end
end
module MyModule
include CreateClassMethodsUponInclude
# ...
@thisismydesign
thisismydesign / create_class_methods_upon_include.rb
Created August 21, 2018 12:43
Ruby: how to use self.included meaningfully, create class methods upon include
def self.included(base)
base.extend(self)
end