Skip to content

Instantly share code, notes, and snippets.

@CodeShane
CodeShane / gist:c51afc417b8d0e24b53c1ee015cec354
Created February 16, 2020 06:24 — forked from cdown/gist:1163649
Bash urlencode and urldecode
urlencode() {
# urlencode <string>
old_lc_collate=$LC_COLLATE
LC_COLLATE=C
local length="${#1}"
for (( i = 0; i < length; i++ )); do
local c="${1:i:1}"
case $c in
[a-zA-Z0-9.~_-]) printf "$c" ;;
@CodeShane
CodeShane / README-oneshot-systemd-service.md
Created March 1, 2019 08:35 — forked from drmalex07/README-oneshot-systemd-service.md
An example with an oneshot service on systemd. #systemd #systemd.service #oneshot

README

Services declared as oneshot are expected to take some action and exit immediatelly (thus, they are not really services, no running processes remain). A common pattern for these type of service is to be defined by a setup and a teardown action.

Let's create a example foo service that when started creates a file, and when stopped it deletes it.

Define setup/teardown actions

Create executable file /opt/foo/setup-foo.sh:

@CodeShane
CodeShane / balloontip.py
Created December 8, 2018 15:04 — forked from boppreh/balloontip.py
Balloon tip module, Python, using win32gui. Display a notification in the tray bar and quits after 10 seconds.
# -- coding: utf-8 --
from win32api import *
from win32gui import *
import win32con
import sys, os
import struct
import time
class WindowsBalloonTip:
@CodeShane
CodeShane / Visual Studio solution file headers
Last active September 19, 2018 17:07 — forked from DanAtkinson/Visual Studio solution file headers
Visual Studio solution file headers - 2010, 2012, 2013, 2015, 2017
=verified all libs through ipc 20180919 version are included in this list, not that we have all these headers=
== Visual Studio 2005 (DO NOT COPY THIS LINE) ==
Microsoft Visual Studio Solution File, Format Version 9.00
# Visual Studio 2005
== Visual Studio 2010 (DO NOT COPY THIS LINE) ==
Microsoft Visual Studio Solution File, Format Version 11.00
@CodeShane
CodeShane / sql-mongo_comparison.md
Created September 10, 2018 23:07 — forked from aponxi/sql-mongo_comparison.md
MongoDb Cheat Sheets

SQL to MongoDB Mapping Chart

SQL to MongoDB Mapping Chart

In addition to the charts that follow, you might want to consider the Frequently Asked Questions section for a selection of common questions about MongoDB.

Executables

The following table presents the MySQL/Oracle executables and the corresponding MongoDB executables.

@CodeShane
CodeShane / bobp-python.md
Created July 30, 2018 00:14 — forked from sloria/bobp-python.md
A "Best of the Best Practices" (BOBP) guide to developing in Python.

The Best of the Best Practices (BOBP) Guide for Python

A "Best of the Best Practices" (BOBP) guide to developing in Python.

In General

Values

  • "Build tools for others that you want to be built for you." - Kenneth Reitz
  • "Simplicity is alway better than functionality." - Pieter Hintjens
@CodeShane
CodeShane / request_handler_test.py
Created July 30, 2018 00:14 — forked from didip/request_handler_test.py
Testing Tornado RequestHandlers
import unittest, os, os.path, sys, urllib
import tornado.database
import tornado.options
from tornado.options import options
from tornado.testing import AsyncHTTPTestCase
# add application root to sys.path
APP_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
sys.path.append(os.path.join(APP_ROOT, '..'))
@CodeShane
CodeShane / bottle_hello.py
Created July 30, 2018 00:14 — forked from drgarcia1986/bottle_hello.py
Python HelloWorld (WebFrameworks) Collection
# -*- coding: utf-8 -*-
from bottle import route, run
@route('/')
def index():
return '<h1>Hello World/h1>'
run(host='localhost', port=8000)
@CodeShane
CodeShane / gist:639d6904cbaa037881c400e9fa0e85c2
Created July 30, 2018 00:11 — forked from sirleech/gist:2660189
Python Read JSON from HTTP Request of URL
# Load Json into a Python object
import urllib2
import json
req = urllib2.Request("http://localhost:81/sensors/temperature.json")
opener = urllib2.build_opener()
f = opener.open(req)
json = json.loads(f.read())
print json
print json['unit']
@CodeShane
CodeShane / parse_yaml.sh
Created July 30, 2018 00:09 — forked from pkuczynski/LICENSE
Read YAML file from Bash script
#!/bin/sh
parse_yaml() {
local prefix=$2
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
awk -F$fs '{
indent = length($1)/2;
vname[indent] = $2;
for (i in vname) {if (i > indent) {delete vname[i]}}