Skip to content

Instantly share code, notes, and snippets.

View sideshowcoder's full-sized avatar
💭
🐱

Philipp Fehre sideshowcoder

💭
🐱
View GitHub Profile
@sideshowcoder
sideshowcoder / Readme.md
Created February 13, 2014 10:04
Run vim reindent and retab from command line

Reindent and retab any file with vim from the shell

Vim has some pretty nice standarts on what indention etc. should look like, so it might make sense to run those from the command line on files without haveing to launch vim by hand. This is how it is done:

$ vim myfile.rb -s format.vim

Will execute all the commands specified in format.vim against the myfile.rb. The commands can be anything possible in vim in normal mode, so my example script will reindent the whole file (gg=G) and retab according to the rules, followed by a save.

@sideshowcoder
sideshowcoder / run_eunit.sh
Created February 23, 2014 12:48
Run Erlang EUnit from the shell
# replace ERLANG_MODULE with the module you try to test, i.e. calc
erlc -DTEST ERLANG_MODULE.erl && erl -noshell -pa . -eval "eunit:test(ERLANG_MODULE, [verbose])" -s init stop
package main
import (
"fmt"
"github.com/couchbaselabs/go-couchbase"
"log"
)
func main() {
c, err := couchbase.Connect("http://localhost:8091")
@sideshowcoder
sideshowcoder / all_teams_view.json
Created April 11, 2014 12:45
Setting up couchbase views programmatically via Rak
{
"_id": "_design/teams",
"language": "javascript",
"views": {
"all": {
"map": "function(doc, meta){ if(doc.type === 'team'){ emit(meta.id, null); } }"
}
}
}
@sideshowcoder
sideshowcoder / uniq_acct_numbers.rb
Created April 14, 2014 10:36
Unique account numbers via view in couchbase
# Get a number of unique account numbers via a map / reduce view
#
# foobar bucket contains:
#
# A = {"acct":"123456","name":"John Smith"}
# B = {"acct":"123456","name":"John Smith"}
# C = {"acct":"123457","name":"Jane Doe"}
#
# map:
#
@sideshowcoder
sideshowcoder / cb-test.php
Created May 6, 2014 11:19
Couchbase PHP test
<?php
$cb = new Couchbase("127.0.0.1:8091", "", "", "default");
$cb->set("foo", "bar");
var_dump("foo");
@sideshowcoder
sideshowcoder / php.ini
Created May 6, 2014 13:42
Couchbase lib in PHP.ini
....
;extension=php_exif.dll ; Must be after mbstring as it depends on it
extension=php_mysql.dll
extension=php_mysqli.dll
;extension=php_oci8.dll ; Use with Oracle 10gR2 Instant Client
;extension=php_oci8_11g.dll ; Use with Oracle 11gR2 Instant Client
;Couchbase
extension=php_couchbase.dll
def database
return @database if @database
manager = CBLManager.sharedInstance
error_ptr = Pointer.new(:object)
@database = manager.databaseNamed("todos", error: error_ptr)
unless @database
error = error_ptr[0]
alert = UIAlertView.alloc.initWithTitle("Local Database Error",
message:"No access to local database. #{error}",
def authenticate &block
account_store = ACAccountStore.alloc.init
fb_account_type = account_store.accountTypeWithAccountTypeIdentifier( ACAccountTypeIdentifierFacebook)
facebook_options = {}
facebook_options[ACFacebookAppIdKey] = @application_id
facebook_options[ACFacebookPermissionsKey] = ["email"]
account_store.requestAccessToAccountsWithType(fb_account_type, options:facebook_options, completion: lambda do |granted, error|
if granted
accounts = account_store.accountsWithAccountType(fb_account_type)
def start_replication
@pull = @database.createPullReplication(sync_url)
@pull.continuous = true
@push = @database.createPushReplication(sync_url)
@push.continuous = true
listen_for_replication_events @pull
listen_for_replication_events @push