An introduction to curl using GitHub's API
Makes a basic GET request to the specifed URI
curl https://api.github.com/users/caspyin
if request.headers['Content-Type'] == 'application/json': | |
request_data = request.get_json() | |
user_id = request_data['user_id'] | |
msg = request_data['message'] | |
else: | |
user_id = request.form['user_id'] | |
msg = requ |
def exception_catcher(func): | |
def inner_func(*args, **kwargs): | |
try: | |
func(*args, **kwargs) | |
return True, None | |
except Exception as inst: | |
return False, inst | |
return inner_func | |
@exception_catcher |
require "net/http" | |
require "uri" | |
uri = URI.parse("http://google.com/") | |
http = Net::HTTP.new(uri.host, uri.port) | |
request = Net::HTTP::Get.new(uri.request_uri) | |
request["User-Agent"] = "My Ruby Script" | |
request["Accept"] = "*/*" |
Two Types of Socket:
UNIX Socket: Communicate between processes within a single local host. No networking capabilities
Berkeley Socket: Communicate between hosts via ports. Creating a Berkeley Socket creates a port and binds to it and the OS subsequently redirects all packages to that port to the bound process.
package_dir = os.path.abspath(os.path.dirname(__file__)) | |
db_dir = os.path.join(package_dir, 'nd_slack.db') | |
# NEED 4 /'s to specify absolute for sqlalchemy! | |
# ex: sqlite:////asdfaijegoij/aerga.db | |
# NEED 3 /'s for relative paths | |
# path has a / at the beginning so we have 3 here | |
SQLITE_DB = ''.join(['sqlite:///', db_dir]) |
if you move 0 to index i there results in 2 cases: | |
i moved to 0: then the problem is reduced to n-2 (2 elements have swapped and are guaranteed to be in different positions) | |
i moved to somewhere else: problem is reduced to n-1 (n-1 slots left) |
:set ft=filetype | |
:set relativenumber |
document.getElementById("upload-files").value = ""; |
import simplejson as json | |
s = "{'username':'dfdsfdsf'}" #1 INCORRECT, uses '' for quotes in strings | |
s = '{"username":"dfdsfdsf"}' #2 CORRECT, uses "" for quotes in strings | |
j = json.loads(s) |