Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python
from fnmatch import fnmatch
import sys
matched = False
with open('.testignore') as ignore:
for pattern in ignore:
if fnmatch(sys.argv[2], pattern.strip()):
matched = True
break

Keybase proof

I hereby claim:

  • I am nigelbabu on github.
  • I am nigelb (https://keybase.io/nigelb) on keybase.
  • I have a public key whose fingerprint is 7C28 A588 42BA 7E00 7FC8 58EC 3181 30D0 CE77 562F

To claim this, I am signing this object:

@nigelbabu
nigelbabu / export.sql
Last active November 20, 2018 08:19
Migrating from H2 into PostgreSQL
CALL CSVWRITE('/tmp//migrate/ACCOUNTS', 'SELECT * FROM ACCOUNTS');
CALL CSVWRITE('/tmp//migrate/ACCOUNT_DIFF_PREFERENCES', 'SELECT * FROM ACCOUNT_DIFF_PREFERENCES');
CALL CSVWRITE('/tmp//migrate/ACCOUNT_EXTERNAL_IDS', 'SELECT * FROM ACCOUNT_EXTERNAL_IDS');
CALL CSVWRITE('/tmp//migrate/ACCOUNT_GROUPS', 'SELECT * FROM ACCOUNT_GROUPS');
CALL CSVWRITE('/tmp//migrate/ACCOUNT_GROUP_BY_ID', 'SELECT * FROM ACCOUNT_GROUP_BY_ID');
CALL CSVWRITE('/tmp//migrate/ACCOUNT_GROUP_BY_ID_AUD', 'SELECT * FROM ACCOUNT_GROUP_BY_ID_AUD');
CALL CSVWRITE('/tmp//migrate/ACCOUNT_GROUP_MEMBERS', 'SELECT * FROM ACCOUNT_GROUP_MEMBERS');
CALL CSVWRITE('/tmp//migrate/ACCOUNT_GROUP_MEMBERS_AUDIT', 'SELECT * FROM ACCOUNT_GROUP_MEMBERS_AUDIT');
CALL CSVWRITE('/tmp//migrate/ACCOUNT_GROUP_NAMES', 'SELECT * FROM ACCOUNT_GROUP_NAMES');
CALL CSVWRITE('/tmp//migrate/ACCOUNT_PATCH_REVIEWS', 'SELECT * FROM ACCOUNT_PATCH_REVIEWS');
@nigelbabu
nigelbabu / ckan_apache.conf
Last active December 10, 2021 11:52
Running CKAN with SSL
WSGISocketPrefix /var/run/wsgi
<VirtualHost 127.0.0.1:8080>
ServerName myinstance.ckan.net
ServerAlias www.myinstance.ckan.net
WSGIScriptAlias / /etc/ckan/default/apache.wsgi
# pass authorization info on (needed for rest api)
WSGIPassAuthorization On
@nigelbabu
nigelbabu / keybase.md
Created March 15, 2014 02:58
keybase.md

Keybase proof

I hereby claim:

  • I am nigelbabu on github.
  • I am nigelb (https://keybase.io/nigelb) on keybase.
  • I have a public key whose fingerprint is B56F A933 0BC3 2826 6E45 34DB 7CCD F059 5F29 8CF1

To claim this, I am signing this object:

@nigelbabu
nigelbabu / example
Created March 10, 2014 00:22
Purging a group
curl -H 'Authorization: yourapikeyhere' http://demo.ckan.org/api/action/group_purge -d '{"id": "test-test-test-test-tes-t"}'
# Alternatively, you can also use the ckanapi
import ckanapi
ckan = ckanapi.RemoteCKAN('http://demo.ckan.org', apikey='yourapikey')
result = ckan.action.group_purge(id='test-test-test-test')
print result
class PartnerGroupClass(plugins.SingletonPlugin, DefaultGroupForm):
plugins.implements(plugins.IGroupForm, inherit=True)
## IGroupForm
def is_fallback(self):
return True
def group_types(self):
return ['organization']
@nigelbabu
nigelbabu / lambdafun.py
Created November 30, 2013 17:31
Demonstrating some fun with python lambda
#!/usr/bin/env python
def with_lambda(hours=[]):
days = map(lambda x: x/8.0, hours)
total_days = reduce(lambda x, y: x+y, days)
return days, total_days
def without_lambda(hours=[]):
@nigelbabu
nigelbabu / reorder.py
Created September 30, 2013 05:55
Quick script to reverse the order of resources in a CKAN dataset.
#!/usr/bin/env python
import requests
import json
def main():
# Change this to actual API key
apikey = 'XXX'
# Change if required to correct CKAN url. No trailing slash.
ckan_url = 'http://127.0.0.1:5000'
# with lambda
pkg_dict['resources'] = filter(lambda x: x.get('id') != id, pkg_dict.get('resources', []))
#without lambda
for res in pkg_dict.get('resources', []):
if res.get('id') == id:
pkg_dict['resources'].remove(id)