- GitHub Staff
- https://bento.me/kyanny
- @kyanny
- in/kyanny
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Usage: bash graphql.sh < query.txt | |
query=$(cat - | sed -e 's/"/\\"/g' | tr -d '\n') | |
cat <<EOM> query.json | |
{"query":"$query"} | |
EOM | |
curl -H "Authorization: token $GITHUB_TOKEN" https://api.github.com/graphql -d @query.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ref. https://gist.github.com/mdonkers/63e115cc0c79b4f6b8b3a6b797e485c7 | |
# ref. https://stackoverflow.com/questions/54607547/read-http-request-data-in-python-3 | |
import http.server | |
import socketserver | |
import logging | |
import os | |
import urllib.parse | |
PORT = os.getenv("PORT", 8080) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env deno run --allow-net | |
// https://deno.land/manual/examples/http_server | |
// Start listening on port 8080 of localhost. | |
const server = Deno.listen({ port: 8080 }); | |
console.log(`HTTP webserver running. Access it at: http://localhost:8080/`); | |
// Connections to the server will be yielded up as an async iterable. | |
for await (const conn of server) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib.request | |
import os | |
import json | |
token = os.getenv('GITHUB_TOKEN') | |
data = { | |
'text': '**hello** __world__', | |
} | |
headers = { | |
'Content-Type': 'application/json', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib.request | |
import os | |
import json | |
token = os.getenv('GITHUB_TOKEN') | |
headers = { | |
'Authorization': f'token {token}' | |
} | |
url = 'https://api.github.com/user/repos' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HelloWorld: | |
def __init__(self, name): | |
self.name = name.capitalize() | |
def sayHi(self): | |
print "Hello " + self.name + "!" | |
hello = HelloWorld("world") | |
hello.sayHi() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tempfile | |
with tempfile.NamedTemporaryFile() as tmp: | |
print(tmp.name) | |
tmp.write(b'Hello\nWorld') | |
tmp.seek(0) | |
with open(tmp.name) as f: | |
print(f.read()) | |
with tempfile.NamedTemporaryFile(mode='w+t') as tmp: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'uri' | |
url = 'http://example.com?foo=1&bar=2' | |
uri = URI.parse(url) | |
decoded_query = URI.decode_www_form(uri.query) | |
pp decoded_query, decoded_query.class | |
decoded_query_hash = Hash[decoded_query] | |
pp decoded_query_hash, decoded_query_hash.class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def should_hit(dealer_total, player_total, player_low_aces, player_high_aces): | |
"""Return True if the player should hit (request another card) given the current game | |
state, or False if the player should stay. | |
When calculating a hand's total value, we count aces as "high" (with value 11) if doing so | |
doesn't bring the total above 21, otherwise we count them as low (with value 1). | |
For example, if the player's hand is {A, A, A, 7}, we will count it as 11 + 1 + 1 + 7, | |
and therefore set player_total=20, player_low_aces=2, player_high_aces=1. | |
""" | |
if dealer_total >= player_total or player_total <= 12: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# numbers | |
def generate_random_numbers(length) | |
chars = (0..9).to_a.map(&:to_s) | |
length.times.map{ chars.shuffle.first }.join | |
end | |
# lowercase letters | |
def generate_random_lowercase_letters(length) |