Skip to content

Instantly share code, notes, and snippets.

View nickhargreaves's full-sized avatar
👨‍💻

Nick Hargreaves nickhargreaves

👨‍💻
View GitHub Profile
import 'package:beyonic_flutter_library/beyonicservice.dart';
import 'package:beyonic_flutter_library/models/payments.dart';
beyonic_service = BeyonicService(apiKey: your_api_key);
// load list of payments
Future <List<Payment>> _payments = beyonic_service.load(Payment.all, offset: 0);
// load single payment
Future <Payment> _payment = beyonic_service.load(Payment.single);
class MainActivity : AppCompatActivity() {
private lateinit var mResultTextView: TextView
private lateinit var mPhonenumberTextView: TextView
private var b: Boolean? = false
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
{% load qr_code %}
<h1>SpaceShips</h1>
<ul>
{% for spaceship in object_list %}
<li>
{{ spaceship.model }}
{% qr_from_text spaceship.pk size=8 version=12 %}
</li>
{% empty %}
<li>No spaceships yet.</li>
class SpaceShipListView(ListView):
model = SpaceShip
class SpaceShipPayment(View):
def get(self, request, *args, **kwargs):
"""
Get the item_id and phone_number from request to create a new payment
:param request:
:param args:
@receiver(post_save, sender=Payment)
def call_payment_api(sender, instance, created, **kwargs):
if created:
# Initiate a Beyonic Collection Request to request money from the user
import beyonic
beyonic.api_key = settings.BEYONIC_API_KEY
response = beyonic.CollectionRequest.create(
phonenumber=instance.phone_number,
amount=instance.item.price,
currency=instance.item.currency,
class SpaceShip(models.Model):
# Sample merchant product
model = models.CharField(max_length=255, blank=False, null=False)
price = models.DecimalField(max_digits=99, decimal_places=2)
currency = models.CharField(max_length=55, default='KES', blank=False, null=False)
def __str__(self):
return self.model
import base64
import datetime
import json
from django.conf import settings
import requests
import uuid
def make_request(url, data, request_date, msisdn, pin):
@nickhargreaves
nickhargreaves / geocode_db_list.php
Last active January 27, 2016 10:30
Scrapper for geocoding list with multiple location columns
<?php
/**
* Scrapper for geocoding list with multiple location columns
* If a finer location fails, it settles for the next best thing
*
* @author http://twitter.com/nickhargreaves
*/
//Db connection
$link = mysql_connect("", "", "");
{"checklists":[{"id":"1","name":"Category 1","items":[{"id":"1","text":"question1"},{"id":"2","text":"question2"},{"id":"3","text":"question3"}]},{"id":"2","name":"Category 2","items":[{"id":"4","text":"question4"},{"id":"5","text":"question5"}]}]}
<?php
$link = mysql_connect('localhost', '', '');
mysql_select_db('');
$create_table = "CREATE TABLE IF NOT EXISTS `json` (
`id` int(11) NOT NULL,
`reporting-org_type` text NOT NULL,
`reporting-org_ref` text NOT NULL,
`reporting-org_text` text NOT NULL,
`iati-identifier` text NOT NULL,