Skip to content

Instantly share code, notes, and snippets.

View tim-hub's full-sized avatar
:octocat:
Patience is Love

Tim tim-hub

:octocat:
Patience is Love
View GitHub Profile
@tim-hub
tim-hub / handle_update_failover.py
Last active February 21, 2017 07:59
insert to replica set, and catach errors
#!/usr/bin/env python
"""
Updates documents in a safe manner and catches expected errors.
"""
import pymongo
import time
# Previous code; left here for reference.
import pymongo
import sys
c = pymongo.MongoClient(host=["mongodb://localhost:27017",
"mongodb://localhost:27018",
"mongodb://localhost:27019"],
replicaSet="m101",
w=1,
j=True)
@tim-hub
tim-hub / see.sh
Created February 19, 2017 08:51
see mongod running
ps -ef | grep mongod
@tim-hub
tim-hub / using_gridfs.py
Created January 25, 2017 07:44
mongodb use gridfs pymongo
#!/usr/bin/env python
import pymongo
import gridfs
# establish a connection to the database
connection = pymongo.MongoClient()
#get a handle to the test database
db = connection.test
@tim-hub
tim-hub / uikit offcanvas hide and show.html
Created January 14, 2017 09:21
uikit offcanvas example, with hide the offcanvas and the nav parent and sub example
<div id="offcanvas_side_nav" class="uk-offcanvas">
<div class="uk-offcanvas-bar uk-offcanvas-bar-flip">
<div class="uk-offcanvas-bar">
<ul class="uk-nav uk-nav-offcanvas uk-nav-parent-icon" data-uk-nav>
<li class="uk-nav-header">
<a class="button_link_like"
id="turn_off_offcanvas"
@tim-hub
tim-hub / gist:71c263203b55a91a531e5def1aabd770
Created December 29, 2016 02:26 — forked from skyuplam/gist:ffb1b5f12d7ad787f6e4
Flask-Security and Flask-Admin example by Steve Saporata
# Example of combining Flask-Security and Flask-Admin.
# by Steve Saporta
# April 15, 2014
#
# Uses Flask-Security to control access to the application, with "admin" and "end-user" roles.
# Uses Flask-Admin to provide an admin UI for the lists of users and roles.
# SQLAlchemy ORM, Flask-Mail and WTForms are used in supporting roles, as well.
from flask import Flask, render_template
from flask.ext.sqlalchemy import SQLAlchemy
@tim-hub
tim-hub / detect.py
Created December 19, 2016 22:45 — forked from LeZuse/detect.py
Flask browser detection
browser = request.user_agent.browser
version = request.user_agent.version and int(request.user_agent.version.split('.')[0])
platform = request.user_agent.platform
uas = request.user_agent.string
if browser and version:
if (browser == 'msie' and version < 9) \
or (browser == 'firefox' and version < 4) \
or (platform == 'android' and browser == 'safari' and version < 534) \
or (platform == 'iphone' and browser == 'safari' and version < 7000) \
@tim-hub
tim-hub / ARKeySetter Intro.md
Created August 26, 2016 04:07
This script is for vuforia to set the vuforia api key.

If you want to set the key, but not want to share the key to the public, you need this.

  1. put it on ARCamera, and give it the first priority in components
  2. put your key as apiKey.txt file in Builds folder
using System.Net;
public string GetHtmlFromUri(string resource)
{
string html = string.Empty;
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(resource);
try
{
using (HttpWebResponse resp = (HttpWebResponse)req.GetResponse())
{
bool isSuccess = (int)resp.StatusCode < 299 && (int)resp.StatusCode >= 200;
@tim-hub
tim-hub / MiniJSON.cs
Created May 31, 2016 10:25 — forked from darktable/MiniJSON.cs
Unity3D: MiniJSON Decodes and encodes simple JSON strings. Not intended for use with massive JSON strings, probably < 32k preferred. Handy for parsing JSON from inside Unity3d.
/*
* Copyright (c) 2013 Calvin Rien
*
* Based on the JSON parser by Patrick van Bergen
* http://techblog.procurios.nl/k/618/news/view/14605/14863/How-do-I-write-my-own-parser-for-JSON.html
*
* Simplified it so that it doesn't throw exceptions
* and can be used in Unity iPhone with maximum code stripping.
*
* Permission is hereby granted, free of charge, to any person obtaining