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
"platform": "cmdSwitch2",
"name": "CMD Switch",
"switches": [{
"name" : "Projector",
"on_cmd": "sudo echo -ne \"* 0 IR 001\r\" > /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_AL00M6F3-if00-port0",
"off_cmd": "sudo echo -ne \"* 0 IR 002\r\" > /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_AL00M6F3-if00-port0",
"state_cmd": ": $(rm ~/.projector;timeout 2s cat < /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_AL00M6F3-if00-port0 > ~/.projector & sleep 0.5;sudo echo -ne \"* 0 Lamp ?\r\" > /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_AL00M6F3-if00-port0; sleep 1.5) && grep 'Lamp 1' ~/.projector",
"polling": true,
"interval": 5,
"timeout": 4000,
@Cosmo
Cosmo / gist:7300e1d64869bd142ae6
Last active December 4, 2015 10:20
All Public CG-Structs and NS-Classes in OpenSource Swift 2.2
devran@ubuntu:~/projects/Hello$ swift
Welcome to Swift version 2.2-dev (LLVM 46be9ff861, Clang 4deb154edc, Swift 778f82939c). Type :help for assistance.
1> import Foundation
2> CG
Available completions:
CGFloat
CGPoint
CGRect
CGRectEdge
CGSize
@Cosmo
Cosmo / m3u.swift
Last active August 21, 2023 09:59
Swift M3U Parser
struct MediaItem {
var duration: Int?
var title: String?
var urlString: String?
static func parseM3U(contentsOfFile: String) -> [MediaItem]? {
var mediaItems = [MediaItem]()
contentsOfFile.enumerateLines({ line, stop in
if line.hasPrefix("#EXTINF:") {
let infoLine = line.stringByReplacingOccurrencesOfString("#EXTINF:", withString: "")
@Cosmo
Cosmo / intsplitter.swift
Last active October 17, 2015 00:47
split int by array of ints
struct NumberComposition {
var value: Int
var numbers: [Int]
var composition: [Int] {
return generateComposition()
}
init(of value: Int, fromNumbers numbers: [Int]) {
self.value = value
self.numbers = numbers
@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)
@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":
# 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
# 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 }";
}
@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)
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