Skip to content

Instantly share code, notes, and snippets.

View sled's full-sized avatar

Simon Schmid sled

  • Zurich, Switzerland
View GitHub Profile
# frozen_string_literal: true
source 'https://rubygems.org'
ruby '>= 2.7'
gem 'stringio', '3.0.2'
# Put this in app/types/types/address.rb then
# rails c
# Types::Address.new
# (change zip to Types::String)
# reload!
# Types::Address.new
module Types
class Address < Dry::Types::Struct
constructor_type(:schema)
class User < Dry::Types::Struct
attribute :name, Types::String
attribute :birth_day, Types::Date
end
UserSchema = Dry::Validation.Schema do
key(:name).required
key(:birth_date).required(:date?)
end
class User < Dry::Types::Struct
attribute :name, Types::String
attribute :birth_day, Types::Date
end
class User < Dry::Types::Struct
attribute :name, Types::String
attribute :birth_date, Types::Coercible::Date
end
@sled
sled / refile_rotate.rb
Last active December 17, 2015 21:19
puts this under app/config/initializers/refile_rotate.rb
Refile::MiniMagick.prepend Module.new {
define_method('rotate') do |img, angle=0|
img.combine_options do |cmd|
yield cmd if block_given?
cmd.rotate angle
end
end
define_method('fill_rotate') do |img, width, height, angle=0, gravity="Center"|
# We use `convert` to work around GraphicsMagick's absence of "gravity"
@sled
sled / secure_compare.rb
Created November 17, 2015 08:25
Constant time comparisons
# constant-time comparison algorithm to prevent timing attacks
def self.secure_compare(a, b)
return false if a.blank? || b.blank? || a.bytesize != b.bytesize
l = a.unpack "C#{a.bytesize}"
res = 0
b.each_byte { |byte| res |= byte ^ l.shift }
res == 0
end
end
@sled
sled / 0_reuse_code.js
Created November 16, 2015 10:27
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@sled
sled / check.rb
Created October 5, 2015 13:25
Checks whether a mail is probably a google apps email
#!/usr/bin/env ruby
require 'resolv'
require 'public_suffix'
email = ARGV[0]
domain = email.split("@").last
servers = %w(googlemail.com, google.com)
apr:
osx:
homebrew:
packages: []
assimp:
osx:
homebrew:
packages: [assimp]
assimp-dev:
osx:
diff -r edccf8cc52e3 CMake/Packages/FindFreetype.cmake
--- a/CMake/Packages/FindFreetype.cmake Fri Jun 20 00:53:20 2014 +0200
+++ b/CMake/Packages/FindFreetype.cmake Fri Oct 03 01:19:56 2014 +0200
@@ -43,7 +43,7 @@
findpkg_framework(FREETYPE)
message(STATUS "CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}")
-find_path(FREETYPE_INCLUDE_DIR NAMES freetype/freetype.h HINTS ${FREETYPE_INC_SEARCH_PATH} ${FREETYPE_PKGC_INCLUDE_DIRS} PATH_SUFFIXES freetype2)
+find_path(FREETYPE_INCLUDE_DIR NAMES freetype.h HINTS ${FREETYPE_INC_SEARCH_PATH} ${FREETYPE_PKGC_INCLUDE_DIRS} PATH_SUFFIXES freetype2)
find_path(FREETYPE_FT2BUILD_INCLUDE_DIR NAMES ft2build.h HINTS ${FREETYPE_INC_SEARCH_PATH} ${FREETYPE_PKGC_INCLUDE_DIRS})