This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module URI | |
| def self.parse(uri) | |
| uri = "#{uri}/" unless uri.index("/") | |
| uri = "http://#{uri}" unless uri.index("://") | |
| scheme, userinfo, host, port, | |
| registry, path, opaque, query, fragment = self.split(uri) | |
| if scheme && @@schemes.include?(scheme.upcase) | |
| @@schemes[scheme.upcase].new(scheme, userinfo, host, port, | |
| registry, path, opaque, query, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'daemons' | |
| module Daemons | |
| class Monitor | |
| def stop | |
| pid = @pid.pid | |
| begin; Process.kill('TERM', pid); rescue ::Exception; end | |
| sleep(0.5) | |
| begin; Process.kill('KILL', pid); rescue ::Exception; end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module ActiveRecordExtensions | |
| def self.included(base) | |
| base.extend(ClassMethods) | |
| end | |
| module ClassMethods | |
| def ids(field = nil) | |
| attribute(field ||= "id").map{|id| id.to_i} | |
| end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| require 'benchmark' | |
| Benchmark.bm do |x| | |
| x.report("200 000") do | |
| File.open("out.xml", "w+") do |f| | |
| f << <<-EOF | |
| <?xml version="1.0" encoding="UTF-8"?> | |
| <feed xml:lang="en-US" xmlns:app="http://www.w3.org/2007/app" xmlns="http://www.w3.org/2005/Atom"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| checkBandwidth(#amf{args = [null | Args]} = AMF, #rtmp_session{current_speed = Speed} = State) when is_number(Speed) -> | |
| ?D({"checkBandwidth", Args}), | |
| apps_rtmp:reply(AMF#amf{args = [null, Speed]}), | |
| State; | |
| checkBandwidth(#amf{args = [null | Args]} = AMF, State) when is_number(Speed) -> | |
| ?D({"checkBandwidth", Args}), | |
| apps_rtmp:reply(AMF#amf{args = [null, null]}), | |
| State. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Paperclip | |
| class Attachment | |
| class UploadedPath | |
| attr_reader :original_filename, :content_type, :size, :path | |
| def initialize(uploaded_file) | |
| @original_filename = uploaded_file["name"].downcase | |
| @content_type = uploaded_file["content_type"].to_s.strip | |
| @file_size = uploaded_file["size"].to_i | |
| @path = uploaded_file["path"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| speex_bits_init(&driver->bits); | |
| driver->encoder = speex_encoder_init(&speex_wb_mode); | |
| driver->decoder = speex_decoder_init(&speex_wb_mode); | |
| speex_decoder_ctl(driver->decoder, SPEEX_GET_FRAME_SIZE, &driver->frame_size); | |
| speex_decoder_ctl(driver->decoder, SPEEX_GET_SAMPLING_RATE, &driver->sample_rate); | |
| driver->den = speex_preprocess_state_init(driver->frame_size, driver->sample_rate); | |
| // for each frame: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env escript | |
| -record(test, {q, w,e,r,t,y}). | |
| utime() -> | |
| {_M,S,Mi} = now(), | |
| S*1000000+Mi. | |
| iter1(0, _) -> | |
| done; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env escript | |
| -record(test, {q, w,e,r,t,y}). | |
| some() -> random:uniform(6). | |
| iter1(0, _) -> | |
| done; | |
| iter1(X, V) -> | |
| %io:format(".. ~p~n", [proplists:get_value(random:uniform(6), V)]), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -module(bm_ets). | |
| -export([run/0]). | |
| -include_lib("stdlib/include/ms_transform.hrl"). | |
| run() -> | |
| ETS = fill_ets(), | |
| List = fill_list(), | |
| io:format("Initialized, starting~n"), |