Skip to content

Instantly share code, notes, and snippets.

View cris's full-sized avatar

Sergii Boiko cris

  • Railsware
  • Kyiv, Ukraine
View GitHub Profile
@cris
cris / gist:809309
Created February 3, 2011 10:20
Bug in psych(ruby 1.9.2) with yaml aliased sections
require 'psych'
require 'yaml'
yaml_config = <<-YAML
development: &common
encoding: utf-8
database: dev-base
production:
<<: *common
@cris
cris / gist:818326
Created February 9, 2011 11:15
UTF-8 & UCS-4
require 'iconv'
utf8 = "123 abc привет"
utf8.each_codepoint {|cp| puts cp}
ucs4 = Iconv.iconv("UCS-4", "UTF-8", utf8).first
# s.pack("C*").unpack("N") - get 4bytes from array and pack them into string
# with 4 bytes and then unpack them into one 32bit number
ucs4.each_byte.each_slice(4) {|s| puts s.pack("C*").unpack("N")}
@cris
cris / gist:836768
Created February 21, 2011 07:18
Multi-class in JS
function User() {
this.name = 'Sasha';
}
User.prototype.login = function() {
console.log("Hello, " + this.name);
};
function Admin(self) {
if (self) {
@cris
cris / gist:842052
Created February 24, 2011 11:11
Use of codepoint feature in Ruby 1.9.2
("а".ord.."я".ord).map {|cp| cp.chr('UTF-8')}
# => ["а", "б", "в", "г", "д", "е", "ж", "з", "и", "й", "к", "л", "м", "н", "о", "п", "р", "с", "т", "у", "ф", "х", "ц", "ч", "ш", "щ", "ъ", "ы", "ь", "э", "ю", "я"]
@cris
cris / socketio-worker.conf.sh
Created February 29, 2012 09:20
Socket.IO Upstart job
description "Socket.IO worker"
instance $NUM
stop on stopping socketio
respawn
limit nofile 10000 10000
respawn limit 99 5
kill timeout 5
@cris
cris / connection_pool_fix.rb
Created May 11, 2012 09:48
Fix for broken connection-pool in Rails < 3.3.0
# Monkey patch ConnectionPool#checkout to avoid database connection timeouts
# Source: https://github.com/rails/rails/issues/2547
# For Rails 3.2.0 and upper, You need to check if the pool error still occurs
if Rails.version < "3.3.0"
class ActiveRecord::ConnectionAdapters::ConnectionPool
def checkout
# Checkout an available connection
start_at = Time.now
@connection_mutex.synchronize do
loop do
@cris
cris / build.xml
Last active December 22, 2015 09:58
Simple build.xml for toy java-projects, to have ability to unit-test it via command-line.
<?xml version="1.0" encoding="UTF-8"?>
<!--
build.xml with dead-simple project structure and ability to use JUnit.
This build.xml provides next directories structure:
.
├── build
│   ├── main
│   │   └── SomeClass.class
│   └── test
@cris
cris / pre-commit
Created October 8, 2013 15:03
Prevents commit of "focus: true"/":focus => true"
#!/usr/bin/env ruby
# vim: set syntax=ruby
flag = false
files = `git diff --cached --name-only --diff-filter=ACM | grep "_spec\.rb$"`.split("\n")
files.each do |file|
patterns = ["focus:[ ]*true", ":focus[ ]*=>[ ]*true"]
patterns.each do |pattern|
results = `git diff --cached #{file} | grep "^\+[^+]" | grep "#{pattern}"`.split("\n").map { |r| r.sub(/^\+[\s\t]*/, '') }
@cris
cris / patch-angular-mocks.diff
Created August 10, 2014 23:10
Patch for AngularJS 1.0.7(1.0.8) to make it compatible with Jasmine 2.0
diff --git a/src/ngMock/angular-mocks.js b/src/ngMock/angular-mocks.js
index 41217c7..fe09bc6 100644
--- a/src/ngMock/angular-mocks.js
+++ b/src/ngMock/angular-mocks.js
@@ -1635,13 +1635,28 @@ window.jstestdriver && (function(window) {
window.jasmine && (function(window) {
+ var currentSpec = null,
+ isSpecRunning = function() {
require 'set'
# Remove vowels from string
# Hash-solution with Ruby 2.3
vowels = {'a' => true, 'e' => true, 'i' => true, 'o' => true, 'u' => true}
"cool test".chars.reject(&vowels).join #=> "cl tst"
# Set-solution could be in Ruby 2.3 :)
vowels = Set.new(%w[a e i o u])