Skip to content

Instantly share code, notes, and snippets.

@timothyklim
timothyklim / vk_api.rb
Created August 12, 2011 06:45
vk_api.rb
#!/usr/bin/env ruby
# encode: utf-8
# Vkontakte api class
require 'digest/md5'
require 'json'
require 'rest_client'
class API
attr_reader :app_id, :app_secret
TinyTds::Error: Adaptive Server connection timed out: EXEC sp_executesql N' SELECT DISTINCT columns.TABLE_NAME AS table_name, columns.COLUMN_NAME AS name, columns.DATA_TYPE AS type, columns.COLUMN_DEFAULT AS default_value, columns.NUMERIC_SCALE AS numeric_scale, columns.NUMERIC_PRECISION AS numeric_precision, columns.ordinal_position, CASE WHEN columns.DATA_TYPE IN (''nchar'',''nvarchar'') THEN columns.CHARACTER_MAXIMUM_LENGTH ELSE COL_LENGTH(columns.TABLE_SCHEMA+''.''+columns.TABLE_NAME, columns.COLUMN_NAME) END AS [length], CASE WHEN columns.IS_NULLABLE = ''YES'' THEN 1 ELSE NULL END AS [is_nullable], CASE WHEN CCU.COLUMN_NAME IS NOT NULL AND TC.CONSTRAINT_TYPE = N''PRIMARY KEY'' THEN 1 WHEN COLUMNPROPERTY(OBJECT_ID(columns.TABLE_SCHEMA+''.''+columns.TABLE_NAME), columns.COLUMN_NAME, ''IsIdentity'') = 1 THEN 1 ELSE NULL END AS [is_identity] FROM INFORMATION_SCHEMA.COLUMNS columns LEFT OUTER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS TC ON TC.TABLE_NAME = columns.TABLE_NAME AND TC.CONSTRAINT_TYPE = N''PRIM
@timothyklim
timothyklim / gist:1803412
Created February 11, 2012 18:21
Yandex wordstat example with Ruby mechanize
require 'mechanize'
bot = Mechanize.new
bot.get('http://kiks.yandex.ru/su/')
query = 'seo'
puts bot.get("http://wordstat.yandex.ru/?cmd=words&page=1&text=#{query}").body
@timothyklim
timothyklim / Main.java
Created February 23, 2012 17:48
JGit test with DHT
import org.eclipse.jgit.api.CloneCommand;
import org.eclipse.jgit.api.errors.InvalidRemoteException;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.transport.RemoteConfig;
import org.eclipse.jgit.transport.URIish;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
development:
google:
id: '34234sds343'
secret: 'drgfr'
facebook:
id: '3434'
secret: 'sds'
vkontakte:
id: '132'
secret: '1212'
@timothyklim
timothyklim / deploy.rb
Created March 29, 2012 22:47 — forked from bkutil/deploy.rb
Start and Stop tasks for resque workers and resque scheduler with capistrano deploy hook (without God)
after "deploy:symlink", "deploy:restart_workers"
after "deploy:restart_workers", "deploy:restart_scheduler"
##
# Rake helper task.
# http://pastie.org/255489
# http://geminstallthat.wordpress.com/2008/01/27/rake-tasks-through-capistrano/
# http://ananelson.com/said/on/2007/12/30/remote-rake-tasks-with-capistrano/
def run_remote_rake(rake_cmd)
rake_args = ENV['RAKE_ARGS'].to_s.split(',')
class CreateCategories < ActiveRecord::Migration
def change
create_table :categories do |t|
t.string :name, null: false
t.integer :parent_id
t.timestamps
end
add_index :categories, :title
require 'open-uri'
require 'json'
require 'uri'
KEY = ''
def get_results query, pages = 1
result = []
pages.times do |page|
@timothyklim
timothyklim / Application.scala
Created June 12, 2012 17:22
After I talked with co-author of play with topic subdomains, I was a little bit confused. My current framework doesn't support my thoughts and I was started write some code!
// app/controllers/Application.scala
trait SubdomainController extends Controller {
def WithSubdomain(f: => String => Request[AnyContent] => Result) = Action { implicit request =>
val splitDomain = request.domain.split("\\.")
if (splitDomain.length < 2) {
BadRequest("Domain not found!")
} else {
f(splitDomain.head)(request)
@timothyklim
timothyklim / application_helper.rb
Created June 12, 2012 17:58
Sometimes you need inline images in your single page...
module ApplicationHelper
def inline_image image_path
result = Rails.cache.read "InlineImageBase64::#{image_path}"
if result.present?
result
else
ext = File.extname image_path
image = File.open(Rails.root.join("app/assets/images/#{image_path}"), 'rb').read