Skip to content

Instantly share code, notes, and snippets.

View RKushnir's full-sized avatar

Roman RKushnir

View GitHub Profile
@danilovelozo
danilovelozo / application_record.rb
Last active December 15, 2022 14:42
Battling RecordNotUnique in Rails
class ApplicationRecord < ActiveRecord::Base
attr_writer :created_moments_ago
def created_moments_ago?
@created_moments_ago
end
def self.create_or_take!
where(block_given? && yield).crumby_create!
rescue ActiveRecord::RecordNotUnique
@troyane
troyane / SNER_preparer
Last active February 1, 2023 21:53
Script to prepare Stanford NER to work with your Python and NLTK
#!/bin/bash
mkdir my_project
cd my_project
echo " . . . Downloading file stanford-ner-2014-08-27.zip"
# NOTE: need to update link for further versions
wget http://nlp.stanford.edu/software/stanford-ner-2014-08-27.zip
echo " . . . Unpacking stanford-ner-2014-08-27.zip"
is_weekday = lambda {|day_of_week, time| time.wday == day_of_week}.curry
sunday = is_weekday[0]
monday = is_weekday[1]
tuesday = is_weekday[2]
wednesday = is_weekday[3]
thursday = is_weekday[4]
friday = is_weekday[5]
saturday = is_weekday[6]
@oumu
oumu / Shameless US OST.md
Last active December 24, 2020 14:07
Shameless US OST
@weilu
weilu / spec_helper.rb
Created November 10, 2012 08:12
Configure database_cleaner for a test suite that contains Capybara js specs.
RSpec.configure do |config|
config.use_transactional_fixtures = false
config.before(:suite) do
DatabaseCleaner.clean_with :truncation
end
config.before(:each) do
if example.metadata[:js]
DatabaseCleaner.strategy = :truncation
@malditogeek
malditogeek / gist:3156358
Created July 21, 2012 16:36
Goliath + HAProxy deploy recipe
after "deploy:update", "deploy:cleanup"
after "deploy:update", "foreman:export"
after "deploy:symlink", "update_haproxy_config_symlink"
namespace :deploy do
task :stop do
run "sudo stop goliath_app"
end
task :start do
run "sudo start goliath_app"
Status Code Status Message Symbol
1xx Informational
100 Continue :continue
101 Switching Protocols :switching_protocols
102 Processing :processing
2xx Success
200 OK :ok
201 Created :created
202 Accepted :accepted
@jstorimer
jstorimer / hilong.rb
Last active July 30, 2020 06:52
hilong -- A simply utility to show character counts for each line of input and highlight lines longer than 80 characters.
#!/usr/bin/env ruby
# A simply utility to show character counts for each line of input and
# highlight lines longer than 80 characters.
#
# Written as an example for http://jstorimer.com/2011/12/12/writing-ruby-scripts-that-respect-pipelines.html
#
# Examples:
#
# $ hilong Gemfile