Skip to content

Instantly share code, notes, and snippets.

@Fedcomp
Fedcomp / data.json
Last active Apr 30, 2021
Array comparison in php, javascript, and ruby
View data.json
[
{ "name": "leroy", "kills": 25, "banned": false },
{ "name": "jenkins", "kills": 30, "banned": false },
{ "name": "cheater", "kills": 999, "banned": true },
{ "name": "n00b", "kills": 0, "banned": false }
]
@Fedcomp
Fedcomp / Cargo.toml
Created Jun 27, 2020
tokio-tungstenite simple https example
View Cargo.toml
[package]
name = "tungstenite-example"
version = "0.0.1"
authors = ["Fedcomp"]
edition = "2018"
[dependencies]
tokio-tungstenite = { version = "0.10.1", features = ["tls"] }
tokio = { version = "0.2.21", features = ["full"] }
futures = "0.3.5"
@Fedcomp
Fedcomp / Gemfile
Created Mar 25, 2019
age difference
View Gemfile
# frozen_string_literal: true
source "https://rubygems.org"
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
# gem "rails"
gem 'rails', '~> 5.0'
gem 'pry-byebug'
@Fedcomp
Fedcomp / description.txt
Last active Mar 25, 2019
Rails timestamptz migration
View description.txt
docker-compose --run --rm ruby test.rb
View geo_service.rb
# Geo/RGeo tools
class GeoService
# @!method line(start_point, end_point) Create LineString from start to end points
# @param start_point [RGeo::Geographic::SphericalPointImpl]
# @param end_point [RGeo::Geographic::SphericalPointImpl]
# @return [RGeo::Cartesian::LineStringImpl]
# @!method line_string(points) Create LineString from array of coordinates
# @param points [Array<RGeo::Geographic::SphericalPointImpl>]
# @return [RGeo::Geographic::SphericalLineStringImpl]
delegate :line, :line_string, to: :spherical_factory
@Fedcomp
Fedcomp / hashifier.rb
Created Oct 21, 2018
Hash all files in directory
View hashifier.rb
require 'pathname'
require 'digest'
Pathname.new(Dir.pwd).children.select(&:file?).each do |file|
next if file.basename.to_s.start_with?('hashed_') || file.extname == '.rb'
file_md5 = Digest::MD5.file(file).hexdigest
old_name = file.basename
new_name = "hashed_#{file_md5}_#{old_name}"
puts "#{old_name} -> #{new_name}"
File.rename old_name, new_name
@Fedcomp
Fedcomp / easy_replay_capturing.bat
Created Oct 17, 2017
Simple batch file to create replay folders
View easy_replay_capturing.bat
mkdir %appdata%\Carbon\.debug\replay
mkdir %appdata%\Carbon\Airmech\.debug\replay
mkdir %appdata%\Carbon\AirmechCanary\.debug\replay
mkdir %appdata%\Carbon\AirmechSteam\.debug\replay
@Fedcomp
Fedcomp / .env
Last active Mar 30, 2019
Create docker image with non-root user
View .env
USER_ID=1000
@Fedcomp
Fedcomp / failsafe.rb
Last active Mar 30, 2017
Ruby exception handler that uses exception notifier to send exception notification and silently handles exception on production.
View failsafe.rb
require 'exception_notification/rails'
# Capture errors in production and return nil
module Failsafe
def failsafe(&_block)
yield
rescue => e
# Show errors only during development
if Rails.env.test? || Rails.env.development?
raise e
View code_for_refactor.rb
def save_post_card
binding.pry
card = PostCard.where(:id => params[:post_card_id]).first
if card.nil?
render text: 'Nnot found postcard with provided ID', status: 404
return
end
text_data = params[:text_data]
name = params[:name].strip