Skip to content

Instantly share code, notes, and snippets.

View Cosmo's full-sized avatar
📎
It looks like you're looking at my profile. Would you like help?

Devran Cosmo Uenal Cosmo

📎
It looks like you're looking at my profile. Would you like help?
View GitHub Profile
@Cosmo
Cosmo / gist:2489482
Created April 25, 2012 12:43
pdf to jpg
def convert_to_previews(new_file)
name = File.basename(current_path)
images = Magick::Image.read(current_path) do
self.background_color = "white" # does not work for me :/
end
if images.length > 0
save_path = "#{Rails.root}/public/uploads/#{model.class.to_s.underscore}/file/#{model.id}/slides"
@Cosmo
Cosmo / gist:2864098
Created June 3, 2012 16:34
css dsl for rubymotion
# Inline styles
@calculate_button = UIButton.named(I18n.t(:calculate_button)).style(color: 0xFFFFFF, align: :center, vertical_align: :center, top: 10, left: 30, width: 120, height: 40)
# External styles
# /app/stylesheets/application.rb
class ApplicationStylesheet < Stylesheets::Base
# Stylesheets for UI-Elements
# usage: @element.outfit(:awesome_default)
@Cosmo
Cosmo / gist:2864121
Created June 3, 2012 16:44 — forked from colinta/gist:2864117
css dsl for rubymotion
# Inline styles
@calculate_button = UIButton.named(I18n.t(:calculate_button)).style(color: 0xFFFFFF, align: :center, vertical_align: :center, top: 10, left: 30, width: 120, height: 40)
# External styles
# /app/stylesheets/application.rb
class ApplicationStylesheet < Stylesheets::Base
# Stylesheets for UI-Elements
# usage: @element.outfit(:awesome_default)
def color_with(value=nil, options={})
if options.is_a?(Numeric)
alpha = options.to_f
else
alpha = options.delete(:alpha) || 1
end
if value
if (value.is_a?(String) && value[0] == "#")
value = value.gsub("#", "").to_i(16)
Teacup::Stylesheet.new(:iphone) do
# enable orientations on the root view
style do
left 0
top 0
width 320
height 480
backgroundColor :lightyellow.uicolor
portrait true
@Cosmo
Cosmo / gist:9066274
Last active August 29, 2015 13:56
translate obj-c code to ruby (rubymotion)
// Objective-C
uuid_t myAppUUIDbytes;
NSUUID *myAppUUID = [[NSUUID alloc] initWithUUIDString:@"226834ae-786e-4302-a52f-6e7efc9f990b"];
[myAppUUID getUUIDBytes:myAppUUIDbytes];
# Ruby
myAppUUIDbytes = Array.new(16, 0)
myAppUUID = NSUUID.alloc.initWithUUIDString("226834ae-786e-4302-a52f-6e7efc9f990b")
myAppUUID.getUUIDBytes(myAppUUIDbytes)
# nslog with message
NSLog("Message from watch received: %@", message)
2014-02-21 10:47:01.514 OnTelly Remote[1298:60b] Message from watch received: {
2 = "<PBNumber 0x1650ba50> { value: 41, width: 4, signed: Y }";
}
# UPDATED - IT WORKS
# Thanks to "kuadrosx"!
# #mongoid on chat.freenode.net
class Conversation
include Mongoid::Document
field :name
embeds_many :messages, as: :messagable, :class_name => 'ConversationMessage'
end
@Cosmo
Cosmo / app.rb
Last active August 29, 2015 14:17
hackevents.co parser and calender.
# Create a file, call it "Gemfile" and write these 3 lines, then save it:
source "https://rubygems.org"
gem 'sinatra'
gem 'nokogiri'
# Run
bundle install
# from your terminal
# Create a file called "app.rb" and paste the follow lines (and run it with "ruby app.rb":
@Cosmo
Cosmo / gist:d71f37d1feeaecc43f6b
Created April 4, 2015 10:24
generate sequential images of numbers
require 'RMagick'
include Magick
width = 500
height = 500
start_color = "#333"
end_color = "#000"
fill = Magick::GradientFill.new(0, 0, height, height, start_color, end_color)