Skip to content

Instantly share code, notes, and snippets.

View snatchev's full-sized avatar
🎏
worse is better

Stefan Natchev snatchev

🎏
worse is better
View GitHub Profile
@snatchev
snatchev / SafariApnController.rb
Last active December 30, 2015 20:39
An example Ruby implementation using ZeroPush to send Safari Push Notifications
class SafariApnController < ApplicationController
# When a user allows permission to receive push notifications, a POST request is sent to the following URL:
# webServiceURL/version/pushPackages/websitePushID
# post '/:version/pushPackages/:website_push_id' => 'safari_apn#package'
def package
#return the push package
send_file(File.join(Rails.root, 'public', 'pushPackage.zip'), type: 'application/zip', disposition: 'inline')
end
@snatchev
snatchev / routes.rb
Last active December 16, 2015 07:09
DRYing up your Rails API routes. Rails' routing gives you the ability to add multiple contraints and scopes to routes. These conditions are and'ed together. Meaning all conditions must be true for the route to match. If you want to or them, to have any condition match, you are left with duplicated code. In this example, I wanted both http://api.…
Rails::Application.routes.draw do
def api_endpoints
controller :api do
resources :widget
post :register
get :help
end
end
@snatchev
snatchev / ringbuffer.rb
Last active December 15, 2015 17:10 — forked from eerohele/ringbuffer.rb
class RingBuffer < Array
attr_reader :max_size
def initialize(max_size, enum = nil)
@max_size = max_size
enum.each { |e| self << e } if enum
end
def <<(el)
if @max_size && self.size >= @max_size
@snatchev
snatchev / libuv-tcp-client.c
Created March 27, 2013 16:55
a libuv evented tcp client
#include <stdio.h>
#include <uv.h>
static void on_close(uv_handle_t* handle);
static void on_connect(uv_connect_t* req, int status);
static void on_write(uv_write_t* req, int status);
static uv_loop_t *loop;
static uv_buf_t alloc_cb(uv_handle_t* handle, size_t size) {
/*
robotev.com
*/
//#########################################################################################################
const int _nom_cycles = 3; /// Broii izmerwania ; Minimalen 2; Maksimalen borii 30
Pod::Spec.new do |s|
s.name = 'PocketSVG'
s.version = '0.0.1'
s.license = 'Attribution-ShareAlike 3.0 Unported'
s.summary = 'Easily convert your SVG files into CGPaths, CAShapeLayers, and UIBezierCurves.'
s.homepage = 'https://github.com/arielelkin/PocketSVG'
s.author = { 'Ariel Elkin' => 'ariel@arivibes.com' }
s.source = { :git => 'git://github.com/arielelkin/PocketSVG.git' }
s.ios.source_files = '*.{h,m}'
@snatchev
snatchev / manual_titrator.pde
Created August 26, 2012 16:26
Omortag's titration
/* Titrator manual detector based */
//program statuses
#define WAITING 0
#define WORKING 1
int programStatus;
const int VOLUME = 10; //microliters - titrant
//the outputs pins
@snatchev
snatchev / gist:1316470
Created October 26, 2011 14:08
resque worker devise not eager loading
❷ > QUEUE=* rake resque:work --trace
** Invoke resque:work (first_time)
** Invoke resque:preload (first_time)
** Invoke resque:setup (first_time)
** Execute resque:setup
** Execute resque:preload
rake aborted!
No such file to load -- devise/confirmations_controller
/Users/stefan/.rvm/gems/ruby-1.9.2-p290@my-rails-project/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:306:in `rescue in depend_on'
/Users/stefan/.rvm/gems/ruby-1.9.2-p290@my-rails-project/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:301:in `depend_on'
@snatchev
snatchev / gist:999779
Created May 31, 2011 02:41
Compiling an xcode project and running the iPhone Simulator from the command line
xcodebuild -activetarget -configuration Debug -sdk iphonesimulator4.2
/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app/Contents/MacOS/iPhone\ Simulator -SimulateApplication path_to_your_app/YourFavouriteApp.app/YourFavouriteApp
bind -v | grep keymap | cut -c 12-