Skip to content

Instantly share code, notes, and snippets.

View vitaLee's full-sized avatar

Vitaliy Berov vitaLee

View GitHub Profile
@vitaLee
vitaLee / time_vs_datatime.md
Created August 22, 2017 17:06 — forked from pixeltrix/time_vs_datatime.md
When should you use DateTime and when should you use Time?

When should you use DateTime and when should you use Time?

It's a common misconception that [William Shakespeare][1] and [Miguel de Cervantes][2] died on the same day in history - so much so that UNESCO named April 23 as [World Book Day because of this fact][3]. However because England hadn't yet adopted [Gregorian Calendar Reform][4] (and wouldn't until [1752][5]) their deaths are actually 10 days apart. Since Ruby's Time class implements a [proleptic Gregorian calendar][6] and has no concept of calendar reform then there's no way to express this. This is where DateTime steps in:

>> shakespeare = DateTime.iso8601('1616-04-23', Date::ENGLAND)
=> Tue, 23 Apr 1616 00:00:00 +0000
>> cervantes = DateTime.iso8601('1616-04-23', Date::ITALY)
=> Sat, 23 Apr 1616 00:00:00 +0000
@vitaLee
vitaLee / MyPage.js
Last active August 15, 2017 13:02 — forked from RStankov/MyPage.js
import withModal from 'withModal';
function MyPage({ openModal, closeModal }) {
const onClick = () => openModal(<div>Modal content. <button onClick={this.closeModal}>close</button></div>);
return (
<p>
<h1>Title</h1>
<button onClick={onClick}>open modal</button>
</p>

I highly suspect that the RSpec core team all use black backgrounds in their terminals because sometimes the colors aren’t so nice on my white terminal

I certainly use a black background. I'm not sure about the other RSpec core folks. Regardless, if there are some color changes we can make that would make output look good on a larger variety of backgrounds, we'll certainly consider that (do you have some suggested changes?). In the meantime, the colors are configurable, so you can change the colors to fit your preferences on your machine. First, create a file at

require "timeout"
module WaitSteps
extend RSpec::Matchers::DSL
matcher :become_true do
match do |block|
begin
Timeout.timeout(Capybara.default_wait_time) do
sleep(0.1) until value = block.call
source :rubygems
# We are not loading Active Record, nor Active Resources etc.
# We can do this in any app by simply replacing the rails gem
# by the parts we want to use.
gem "actionpack", "~> 3.2"
gem "railties", "~> 3.2"
gem "tzinfo"
# Let's use thin

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application:

@vitaLee
vitaLee / config.yml
Created December 5, 2013 10:48
Reusing common config blocks in YAML
defaults: &defaults
foo: 1
bar: 2
baz: 3
production:
<<: *defaults
bar: overriden
quz: 4
# RSpec 2.0 syntax Cheet Sheet by http://ApproachE.com
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below)
module Player
describe MovieList, "with optional description" do
it "is pending example, so that you can write ones quickly"
it "is already working example that we want to suspend from failing temporarily" do
pending("working on another feature that temporarily breaks this one")
@vitaLee
vitaLee / ffmpeg_progress.php
Created February 28, 2013 10:55
FFMPEG encoding progress
<?php
$logFile = 'progress_logs/%s.log';
$cmd = "/usr/local/bin/ffmpeg -i %s -y progress_test.m4v 2> %s";
for ($i=1; $i < count($argv); $i++) {
$video = $argv[$i];
$log = sprintf($logFile, $video);
exec(sprintf($cmd, $video, $log), $processOutput, $processStatus);
#!/usr/bin/env ruby
def video_rotation(video_path)
`mediainfo #{video_path} | grep -i rotation`.match(/(\d+)/)
$1.to_i
end
def video_dimensions(video_path)
dimensions = `mediainfo #{video_path} | egrep -i 'width|height'`.scan(/([\d\s]+)pixels/)
portrait_video?(video_path) && dimensions.reverse!