Skip to content

Instantly share code, notes, and snippets.

# Not so good
i=0
while i<=colnum-1 do #adding the columns
database.alter_table tabname.to_sym do
add_column colnames[i], String
i+=1
end
end
# Better
# For given shop, category, competitor shop, old&new prefixes and prefix shop:
# - find urls for category products competitors(by competitorshop_id)
# - generate urls with new prefixes(often 'html' -> 'html?prefix=PR')
# - add urls with prefixes to tasks
# All in one SQL request. Be careful while debugging, young padawan.
# example: shop_id 11245, category_id 1318231, competitorshop_id 12933,
# old_prefix 'pr=Q49', new_prefix 'pr=Q51', prefixshop_id 1390
def fill_prefix_shop_for_competitor(shop_id, category_id, competitorshop_id, old_prefix, new_prefix, prefixshop_id, force = false)
Db.session do |db|
query =<<-SQL
loop do
$stdout.write "content: #{$stdin.read}"
sleep 1
end
@jaturken
jaturken / moy_mir.rb
Last active December 15, 2015 10:09
check_share
def check_share?(url, uid)
# According to documentation from:
# http://api.mail.ru/docs/reference/rest/stream.getByAuthor/
request_url = "http://www.appsmail.ru/platform/api?" + request_params(url, uid)
responce = HTTParty.get(request_url)
end
private
def request_params(url, uid)
@jaturken
jaturken / application.js
Last active December 15, 2015 09:09
moymir.api.stream.share
params = 'app_id='+ mailru.app_id +
'method=stream.share' +
'session_key=' + mailru.session.session_key +
'url=' + encodeURIComponent(data.url)
network_url = 'http://www.appsmail.ru/platform/api?method=stream.share' +
'&app_id=' + mailru.app_id +
'&session_key=' + mailru.session.session_key +
'&sig=' + hex_md5(mailru.session.oid + params + mailru.private_key) +
// '&sig=' + mailru.session.sig +
@jaturken
jaturken / application.js
Created March 25, 2013 08:52
moymir.api.users.hasAppPermission
params = 'app_id='+ mailru.app_id +
'ext_perm=stream' +
'method=users.hasAppPermission' +
'session_key=' + mailru.session.session_key +
'url=' + encodeURIComponent(data.url)
network_url = 'http://www.appsmail.ru/platform/api?method=users.hasAppPermission' +
'&app_id=' + mailru.app_id +
'&session_key=' + mailru.session.session_key +
'&sig=' + hex_md5(mailru.session.oid + params + mailru.private_key) +
@jaturken
jaturken / users_to_pay_query.rb
Created March 7, 2013 16:42
UsersToPayQuery
class UsersToPayQuery
def self.find
# Select users who have no errors in groups, likes and shares, have wmr and have balanse to pay.
# A bit strange indentation. But it's easier to read this SQL in console with this indendation.
User.where("
NOT EXISTS(
SELECT id FROM shares
WHERE shares.error = 1
AND shares.declined = false
AND shares.user_id = users.id)
@jaturken
jaturken / Preferences.sublime-settings
Created November 14, 2012 08:15
Sublime user preferenses
{
"tab_size": 2,
"translate_tabs_to_spaces": true,
"highlight_line": true,
"caret_style": "wide",
"ensure_newline_at_eof_on_save": true
}
@jaturken
jaturken / doe.sublime_snippet
Created November 12, 2012 14:31
Sublime do...end block autocompletion
<snippet>
<content><![CDATA[
do
${1:code}
end]]></content>
<description>do...end block</description>
<tabTrigger>doe</tabTrigger>
<scope>source.ruby</scope>
</snippet>
@jaturken
jaturken / .zshrc
Created November 2, 2012 16:51
.zshrc
# Path to your oh-my-zsh configuration.
ZSH=$HOME/.oh-my-zsh
HISTSIZE=1000
SAVEHIST=1000
setopt append_history
setopt inc_append_history
setopt extended_history
setopt hist_find_no_dups
setopt hist_ignore_all_dups
setopt hist_reduce_blanks