Skip to content

Instantly share code, notes, and snippets.

@s-mage
s-mage / db_create.rb
Last active October 11, 2015 22:58
Scrzy classifier. Looks bad, works bad, I need to remake it.
#encoding: utf-8
require 'sequel'
def create_model
DB = Sequel.sqlite('aw.db')
DB.create_table(:authors) do
#creating table of authors
primary_key :id, type: Integer, index: true
String :name, unique: true
@s-mage
s-mage / video2mathcad.cpp
Created March 12, 2013 15:43
Pornodance with openCV and mathcad possibility tu create user DLL. I don't know, how to compile it in windows.
#include "MCADINCL.H"
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
// Reading frame and convert it into MathCad matrix(complexarray).
//
LRESULT video2MathCad(COMPLEXARRAY * const result, const char * path_to_video,
const int frame_number)
{
CvCapture* capture = cvCreateFileCapture(path_to_video);
@s-mage
s-mage / analyze.rb
Last active December 19, 2015 08:29
mraztem -- bad copy of mystem with ruby and sqlite.
#!/usr/bin/env ruby
# encoding: utf-8
require 'sequel'
require 'msgpack'
require 'benchmark'
require 'ruby-prof'
require 'logger'
def analyze(word)
@s-mage
s-mage / probability_distribution.rb
Last active December 19, 2015 19:49
Simple implementation of probability distribution.
weights = Array.new(2288) { |x| 1 / 2288.0 }
t = 0.0
weights.map! { |x| t += x; t }
random_value = Random.new.rand
weights.find_index { |x| random_value - x <= 0 }
@s-mage
s-mage / minkowsky.go
Created August 1, 2013 18:04
Problem 228 at project Euler. Find length of S_1864 + ... + S_1909, where S_[number] is [number]-sided polygon. http://projecteuler.net/problem=228
package main
import (
"math"
"fmt"
)
type Vertex struct {
x float64
y float64
@s-mage
s-mage / run_tags.rb
Last active December 21, 2015 17:09
Set git hook that runs ctags automatically after each pool, commit and checkout. Got from https://gist.github.com/tobias/42308/raw/2e7b7072278a2ba65e9d95597e148498d9ba7654/run_tags.rb and refactore. Need to set it more flexible.
#!/usr/bin/env ruby
# A script to run ctags on all .rb files in a project. Can be run on
# the current dir, called from a git callback, or install itself as a
# git post-merge and post-commit callback.
CTAGS = '/usr/bin/env ctags'
HOOKS = %w{ post-merge post-commit post-checkout }
HOOKS_DIR = '.git/hooks'
def install
vim.o.background = "light"
vim.o.termguicolors = true
if vim.g.colors_name then vim.cmd("hi clear") end
vim.cmd("syntax reset")
vim.g.colors_name = "Boring Tomorrow"
-- Default GUI Colours
%h2.expandall Expand/Collapse All
- @tag.pages.each do |page|
%div{ class: 'title', id: "title_#{page.title}" }
= page.pretty_title
= link_to(" [edit]", controller: 'wiki', action: 'show', |
project_id: page.project, id: page.title)
%div{ class: 'section', id: page.title }
= raw Redmine::WikiFormatting::Textile::Formatter.new(page.text).to_html
:javascript
#!/usr/bin/env ruby
require 'sparql/client'
sparql = SPARQL::Client.new("http://dbpedia.org/sparql")
query = "prefix dbpprop: <http://dbpedia.org/property/>
prefix dbpedia-owl: <http://dbpedia.org/ontology/>
select ?name, ?hdi
where {
?country a dbpedia-owl:Country .
@s-mage
s-mage / 2flickr.rb
Last active January 3, 2016 02:49
Upload photos to flickr.
#!/usr/bin/env ruby
require 'flickraw'
require 'json'
CREATE_API_KEY = 'https://secure.flickr.com/services/apps/create/apply'
CONFIG_FILE = File.expand_path '~/.config/2flickr.json'
def init