Skip to content

Instantly share code, notes, and snippets.

View shalomz's full-sized avatar

Shalom Nyende shalomz

View GitHub Profile
#!/usr/bin/python
"""
This code is part of ros package that subscribes to an image topic
and detects smiles found in the image. Results are then republished to a ros
image topic.
This node is an example of how I prefer to write my ROS nodes, as a single
class with a run function.
@wowkin2
wowkin2 / blockchain.py
Last active May 18, 2018 09:13
Simple implementation of blockchain by example
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import hashlib as hasher
import datetime as date
class Block:
def __init__(self, index, timestamp, data, previous_hash):
self.index = index
self.timestamp = timestamp
@aunyks
aunyks / snakecoin-server-full-code.py
Last active March 8, 2024 19:22
The code in this gist isn't as succinct as I'd like it to be. Please bare with me and ask plenty of questions that you may have about it.
from flask import Flask
from flask import request
import json
import requests
import hashlib as hasher
import datetime as date
node = Flask(__name__)
# Define what a Snakecoin block is
class Block:
@kuldeeprishi
kuldeeprishi / threaded_simple_httpserver.py
Created April 18, 2017 05:07
Threaded Simple HTTPServer
#!/bin/env python
import sys
import SocketServer
import BaseHTTPServer
import SimpleHTTPServer
class ThreadingSimpleServer(SocketServer.ThreadingMixIn,
BaseHTTPServer.HTTPServer):
@dimi-tree
dimi-tree / 01_models.py
Last active November 17, 2020 07:16
Django REST Framework: understaning ModelSerializer
from django.db import models
class Member(models.Model):
# RE: null vs blank
#
# NULL https://docs.djangoproject.com/en/1.10/ref/models/fields/#null
# Avoid using null on string-based fields such as CharField and TextField because
# empty string values will always be stored as empty strings, not as NULL.
#
@ankurk91
ankurk91 / git_remember_password.md
Last active May 17, 2024 03:46
Git credential cache, why type password again and again

Tired of entering password again and again ?

Run this command to remember your password:

git config --global credential.helper 'cache --timeout 28800'

Above command will tell git to cache your password for 8 hours.

@adeekshith
adeekshith / website-monitoring-1
Last active April 2, 2024 16:13 — forked from eriwen/gist:187610
Scripts for website monitoring using Python
#!/usr/bin/env python
# sample usage: checksites.py eriwen.com nixtutor.com yoursite.org
import pickle, os, sys, logging
from httplib import HTTPConnection, socket
from smtplib import SMTP
def email_alert(message, status):
fromaddr = 'you@gmail.com'
@tomchristie
tomchristie / put_as_create.py
Created November 3, 2014 11:55
PUT-as-create mixin class for Django REST framework.
class AllowPUTAsCreateMixin(object):
"""
The following mixin class may be used in order to support PUT-as-create
behavior for incoming requests.
"""
def update(self, request, *args, **kwargs):
partial = kwargs.pop('partial', False)
instance = self.get_object_or_none()
serializer = self.get_serializer(instance, data=request.data, partial=partial)
serializer.is_valid(raise_exception=True)
@martync
martync / Render_to_XLS.py
Created February 9, 2012 14:40
Output an XLS file with XLWT
from django.template import Variable, defaultfilters
from django.http import HttpResponse
import xlwt
def render_to_xls(queryset, filename, fields):
"""
Output an XLS file of the queryset
Usage :
-------
@smukkejohan
smukkejohan / nagios
Created February 6, 2012 19:07
Nagios with Nginx configuration
server {
listen 80;
server_name nagios.example.tld;
access_log /var/log/nginx/nagios.access.log;
error_log /var/log/nginx/nagios.error.log info;
expires 31d;
root /usr/share/nagios3/htdocs;