Skip to content

Instantly share code, notes, and snippets.

@evincarofautumn
evincarofautumn / git-branch-description.sh
Created October 29, 2014 18:18
Show git branch description
#!/bin/sh
if [ $# -ne 1 ]; then
echo 'Usage: git-branch-description <branch name>' >&2
exit 1
fi
EDITOR='cat' git branch --edit-description "$1" | grep -v '^#'
require 'socket'
socket = TCPSocket.new('localhost', 7894)
socket.puts "'B'*50024"
all_data = []
while partial_data = socket.read(2024)
puts partial_data
puts "-------------------------"
all_data << partial_data
@robertjwhitney
robertjwhitney / film.rb
Created April 22, 2012 23:45
Conditionally display an image instead of the file input in an ActiveAdmin has_many association.
# active_admin and formtastic seem kinda picky about displaying both the
# image and the file input together here... in fact, it seems like this
# is the ONLY way to do this? Adding anything else after the image_tag squashes it.
ActiveAdmin.register Film do
form do |f|
f.inputs "Film" do
f.input :title
end
f.has_many :stills do |film_still_form|
@marcostolosa
marcostolosa / addCron.md
Last active April 18, 2019 13:25
Create a Cron Job Using Bash (Shell Script) Automatically Without Interactive Editor

Adding a Cron Job via Shell Script

#write out current crontab
crontab -l > mycron

#echo new cron into cron file
echo "00 09 * * 1-5 echo hello" >> mycron

#install new cron file

1) С какими Rails библиотеками(gem-ами) приходилось работать?

Я не сторонник лишних gems. Если необходим какой-либо несистемный функционал (например, state machine), то вместо того, чтобы тянуть в проект какую-то стороннюю OpenSource либу (которая вместе с нужным функционалом добавляет ненужный потайной функционал "магического характера"), я лучше потрачу тоже самое время на разработку собственной библиотеки, которая может уместиться в 1-3 класса, чем разбираться в коде и в случае багов выяснять, где проблема: "у нас или у них там в геме?". Либо выдеру из гема нужный мне код без лишнего.

Ответ на вопрос:

  • rspec
  • composite_primary_keys
  • omniauth (omniauth-instagram, omniauth-vkontakte, omniauth-google-oauth2)
@c80609a
c80609a / task.md
Last active January 22, 2020 10:46
Rails Junior+ Test

Задача

Необходимо посчитать количество перепостов новости (а-ля в соцсети).

Прикладная структура новости:

  1. Заголовок
  2. Тело новости
  3. Автор
  4. Время создания
@jrus
jrus / gist:2145082
Created March 21, 2012 06:08
sort a javascript array using a decorate-sort-undecorate pattern; especially useful if the sort comparison is expensive to compute
# Accepts a list and a key function to apply to each item,
# and then uses a decorate-sort-undecorate pattern to actually
# do the sorting. Returns a new list. Keeps track of the index
# to make sure the sort is stable.
sort_by = (list, key) ->
cmp = ({key: k_a, index: i_a}, {key: k_b, index: i_b}) ->
if k_a == k_b then i_a - i_b else if k_a < k_b then -1 else 1
decorated = ({item, index, key: key item} for item, index in list)
item for {item} in decorated.sort cmp
@davemo
davemo / app.coffee
Last active March 25, 2020 13:25
Got a .coffee file with JSX? Here's how you can transpile to .js with Reacts JSX parsed.
`/** @jsx React.DOM */`
converter = new Showdown.converter
Comment = React.createClass
render: ->
rawMarkup = converter.makeHtml @props.children.toString()
`<div className="comment">
<h2 className="comment">{this.props.author}</h2>
<span dangerouslySetInnerHTML={{__html: rawMarkup}} />
@dariocravero
dariocravero / Gemfile
Created September 5, 2012 18:48
Minimal sinatra app with puma's config.
source "https://rubygems.org"
gem 'puma'
gem 'sinatra'
@chantastic
chantastic / AudioFileStepSelector.coffee
Created January 18, 2015 19:20
My First React Component
# My First React Component
# Added to this Gist for posterity.
# Extracted from https://github.com/ministrycentered/transposr/commit/fa616871914ac16b72d0d1b035a08e01e337bd07
# January 08, 2014
{ div, input } = React.DOM
AudioFileStepSelector = React.createClass
getInitialState: ->
halfSteps: 2