Skip to content

Instantly share code, notes, and snippets.

@c80609a
c80609a / integer.rb
Created November 8, 2016 11:38 — forked from pithyless/integer.rb
Ruby Integer::MAX and Integer::MIN
class Integer
N_BYTES = [42].pack('i').size
N_BITS = N_BYTES * 16
MAX = 2 ** (N_BITS - 2) - 1
MIN = -MAX - 1
end
p Integer::MAX #=> 4611686018427387903
p Integer::MAX.class #=> Fixnum
p (Integer::MAX + 1).class #=> Bignum
require 'mini_magick'
class Walker
def initialize
@filenames = []
end
def walk(dirname)
@c80609a
c80609a / Input.js
Created March 1, 2017 08:28 — forked from grifdail/Input.js
The best javascript input controller for game. Include gamepad support.
/*
Input.jump = {
key: 32//Space
gamepad: 0// A button on as XBOX360 gamepad
}
dont forget to call
Input.update();
at the end of each frame.
@c80609a
c80609a / custom_seed.rake
Created April 28, 2017 15:15
custom_seed.rake
# lib/tasks/custom_seed.rake
namespace :db do
namespace :seed do
Dir[File.join(Rails.root, 'db', 'seeds', '*.rb')].each do |filename|
task_name = File.basename(filename, '.rb').intern
task task_name => :environment do
load(filename) if File.exist?(filename)
end
end
end
@c80609a
c80609a / app_data.rb
Created May 9, 2017 07:46
Native Ruby-only configuration
module Appdata
# we don't want to instantiate this class - it's a singleton,
# so just keep it as a self-extended module
extend self
# Appdata provides a basic single-method DSL with .parameter method
# being used to define a set of available settings.
# This method takes one or more symbols, with each one being
# a name of the configuration option.
def parameter(*names)
# Rails Engine call
`rails plugin new MY_ENGINE --dummy-path=spec/dummy --skip-test-unit --full --database=mysql`
or `rails plugin new ENGINE_NAME --dummy-path=spec/dummy --skip-test-unit --mountable --database=mysql`
# Configure spec_helper.rb
ENV["RAILS_ENV"] = "test"
require File.expand_path("../dummy/config/environment.rb", __FILE__)
require 'rspec/rails'
@c80609a
c80609a / imagemagick_delegates.md
Last active May 11, 2017 16:43
ImageMagick: no decode delegate for this image format

Не работает ImageMagick: "no decode delegate for this image format".

Ubuntu 12, i686.

  • Для начала проверяем выдачу команды convert -list configure.

Expected result (по полной):

DELEGATES     bzlib fontconfig freetype gs jpeg jng jp2 lcms openexr png rsvg tiff x11 xml wmf zlib
@c80609a
c80609a / google_search_page.js
Last active May 19, 2017 08:57
Tab moves focus to the next search result. #google #chrome #google_search_page #without_mouse #only_keyboard #tab #serp
var f_ready = function() {
var $aa = $('h3.r > a');
//console.log($aa);
var ptr = 0;
$(document).keydown(function(e) {
//console.log(e.keyCode); // tab keyCode = 9
@c80609a
c80609a / app.rb
Created August 15, 2017 13:44
redis helloworld
require 'redis'
redis = Redis.new
redis.flushall
puts 'FLUSHALL...'
redis.hmset('account:1',
'id', '1',
'nickname', 'Alex',
'full_name', 'Alex Alex',
@c80609a
c80609a / redis-setbit-test.coffee
Created August 18, 2017 14:15 — forked from saadullahsaeed/redis-setbit-test.coffee
Testing 'setbit' and 'bitcount' on Redis 2.6
express = require 'express'
redis = require 'redis'
app = express()
requestCount = 0
client = null
#Going to use Date as the Key
getKey= ->
d = new Date()