Skip to content

Instantly share code, notes, and snippets.

View e2's full-sized avatar

Cezary Baginski e2

View GitHub Profile
# encoding: utf-8
def test(a,b)
begin
result = ('テ'.encode(a) << 'テ'.encode(b)).encode('utf-8')
rescue Encoding::CompatibilityError
result = "FAILED!"
end
p "Example: #{a} + #{b}: #{result}"
end
@e2
e2 / .travis.yml
Created February 28, 2012 11:07
Running PhantomJS tests on Travis
language: ruby
rvm:
- 1.9.3
before_script:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
- bundle exec rackup ./test/config.ru 2>/dev/null &
- sleep 2
@e2
e2 / tracking file and dir changes
Last active August 29, 2015 13:59
How to PROPERLY think about watching file and directories for changes
# (For developers) How to PROPERLY think about watching files and directories for changes
Goal: saving people the frustration of getting tools to "correctly" respond to
changes to files or directories.
## How to think about directories
Here's an example TODO file (/home/me/Documents/todo.txt):
@e2
e2 / test_inotify.rb
Last active July 11, 2018 14:55
Script for testing inotify and listen on Linux
gem "rb-inotify"
require 'rb-inotify'
gem "listen"
require "listen"
dir = '.'
Listen.to(dir) do |modified, added, removed|
puts "listen: #{[added, modified, removed].inspect}!"
# HOW TO USE:
#
# 1) save this to /some_path/lib/minitests/autorun.rb
# 2) run your test with RSpec, e.g.
#
# $ RUBYLIB=/some_path/lib rspec -f d test/hello_test.rb
require 'rspec/core'
require 'rspec/matchers'
require 'rspec'
RSpec.configure do |config|
def stub_mod(mod, excluded)
mod.constants.each do |klass_name|
klass = mod.const_get(klass_name)
if klass.is_a?(Class)
unless klass == described_class
unless excluded.include?(klass)
class_double(klass.to_s).as_stubbed_const(transfer_nested_constants: true)
@e2
e2 / guard
Last active August 29, 2015 14:13
Save this as bin/guard inside your projects
#!/usr/bin/env ruby
require 'pathname'
ENV['BUNDLE_GEMFILE'] ||= (Pathname(__FILE__).realpath + '../../Gemfile').to_s
require 'rubygems'
require 'bundler/setup'
while !system(Gem.bin_path('guard', 'guard')) && $?.exitstatus == 2
puts('Restarting guard...')
@e2
e2 / gist:d58ec0374ce58e7c7495
Created April 16, 2015 20:43
Readline thread which didn't respond to kill
```
"NonBlockingInputStreamThread" daemon prio=10 tid=0x00007f55c4018800 nid=0x2294 in Object.wait() [0x00007f55fa726000] [153/516]
java.lang.Thread.State: WAITING (on object monitor) [152/516]
at java.lang.Object.wait(Native Method) [151/516]
- waiting on <0x00000000faca1e98> (a jline.internal.NonBlockingInputStream) [150/516]
at jline.internal.NonBlockingInputStream.run(NonBlockingInputStream.java:278)
set(TUP_LABEL $ENV{TUP_LABEL})
cmake_minimum_required(VERSION 3.2.2)
project(tup)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSQLITE_TEMP_STORE=2")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSQLITE_THREADSAFE=0")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSQLITE_OMIT_LOAD_EXTENSION")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DLUA_USE_MKSTEMP")
@e2
e2 / compile_and_commit_assets.rb
Last active April 22, 2016 15:22
Simple script to help web designers work with and release compiled assets in the same git branch as the source assets.
#!/usr/bin/env ruby
#----------------------------------------------------------------------------
# INFO:
#
# Simple script for web designers working on git repositories where source
# assets and compiled assets have to be stored in the same branch.
#
# The goal: generating assets safely and into a separate commit.
#