Skip to content

Instantly share code, notes, and snippets.

View zgramana's full-sized avatar

Zachary Gramana zgramana

View GitHub Profile
@zgramana
zgramana / replace-headers.sh
Created February 13, 2014 02:10
Shell script that replaces an optional old header with a new header, which includes the name of the file containing the header.
#!/bin/bash
# Replace the old headers with the new ones.
# Find all csharp files, recursively.
# If it has an old header, remove it.
# Then insert the new header which includes
# the current file's name.
for file in $(find . -type f -name '*.cs'); do
fileName=${file##*/} # Split on the path char, and take the last segment.
headerStart='1i \
# begin build properties
# autogenerated by buildinfo.sh
ro.build.id=JWR66N
ro.build.display.id=JWR66N
ro.build.version.incremental=711294
ro.build.version.sdk=18
ro.build.version.codename=REL
ro.build.version.release=4.3
ro.build.date=Sat Jun 15 19:53:50 UTC 2013
ro.build.date.utc=1371326030
@zgramana
zgramana / bash.sh
Created July 23, 2014 19:31
Use a self-signed certificate in Couchbase Lite for iOS
openssl x509 -outform der -in cert.pem -out cert.der
@zgramana
zgramana / ExampleQueryByG.cs
Last active August 29, 2015 14:06
Query Firstname / Lastname for names starting with G
public void PutNPeople(Database db, int n)
{
var lastNames = new[] { "Gramana", "Johnson", "Hunter", "Carter" };
var firstNames = new[] { "Zack", "Bryan", "Greg", "Wayne" };
for (int i = 0; i < n; i++)
{
var doc = new Dictionary<string, object>
{
{ "firstName", firstNames[i % 4] },
@zgramana
zgramana / ssl3_server.py
Last active August 29, 2015 14:08
POODLE test target
# Adapted from http://code.activestate.com/recipes/442473-simple-http-server-supporting-ssl-secure-communica/
'''
SimpleSecureHTTPServer.py - simple HTTP server supporting SSL.
- replace fpem with the location of your .pem server file.
- the default port is 443.
usage: python SimpleSecureHTTPServer.py
'''
import socket, os
{
"type": "product-recommendations",
"product-id": "111",
"recommendations": [
{
"_id": "222",
"name": "Handy Hammer",
"min_price": 3.45,
"currency": "USD",
"quantity": {
void CreateDatabase ()
{
_db = Manager.SharedInstance.GetExistingDatabase (DATABASE_NAME);
if (_db == null)
{
var assembly = Assembly.GetCallingAssembly ();
var resourceName = assembly
.GetManifestResourceNames()
.Where (x => x.EndsWith("couchbase-connect.cblite"))
@zgramana
zgramana / info_swap.js
Created December 9, 2014 17:32
Sync Function Snippets
if (doc.type == "contactexchange") {
// trade access to each user's contact channel
access(doc.userId, "contact-" + doc.localUserId);
access(doc.localUserId, "contact-" + doc.userId);
}
@zgramana
zgramana / TaskExtensions.cs
Last active August 29, 2015 14:16
Task.Delay backport
using System;
using System.Threading.Tasks;
using System.Threading;
namespace Couchbase.Lite.Shared
{
public static class TaskExtensions
{
static int CheckTimeout (TimeSpan timeout)
{
@zgramana
zgramana / couchbase-lite-demo.csx
Last active August 29, 2015 14:19
Simple first script to create a bunch of docs and replicate them.
// Run `scriptcs -install Couchbase.Lite` to fetch Couchbase Lite from Nuget.
#r Couchbase.Lite.dll
using Couchbase.Lite;
var db = Manager.SharedInstance.GetDatabase("scriptcs");
db.RunInTransaction(()=>
{