Skip to content

Instantly share code, notes, and snippets.

View gnilchee's full-sized avatar

Greg Nilchee gnilchee

  • Evernote
  • Woodinville, WA
View GitHub Profile
@gnilchee
gnilchee / whatismyip.coffee
Created March 19, 2017 06:53
Getting your public IP with Nodejs using coffeescript and the result js file for reference (npm install --save coffee-script https)
https = require 'https'
https.get { host: 'api.ipify.org', path: '/?format=json' }, (res) ->
console.log 'statusCode:', res.statusCode
console.log 'content-type:', res.headers['content-type']
data = ''
res.on 'data', (chunk) ->
data += chunk.toString()
res.on 'end', () ->
console.log 'publicIP:', JSON.parse(data)['ip']
@gnilchee
gnilchee / slack_presence_change.py
Created February 25, 2017 23:14
Track users status via slack api firehose (RTM)
#!/usr/bin/env python3
from configparser import ConfigParser
from slackclient import SlackClient
config = ConfigParser()
config.read('slack.conf')
SLACK_TOKEN = config['slack']['SLACK_API_TOKEN']
sc = SlackClient(SLACK_TOKEN)
if sc.rtm_connect():
@gnilchee
gnilchee / post_weather_to_slack.py
Created February 10, 2017 17:20
Using weatherman.py post current conditions to Slack channel using user API token.
#!/usr/bin/env python3
from slackclient import SlackClient
from configparser import ConfigParser
from weatherman import WeatherAPI
config = ConfigParser()
config.read('api_secrets.conf')
SLACK_TOKEN = config['slack']['SLACK_API_TOKEN']
weather = WeatherAPI.get_current_conditions(90210)
@gnilchee
gnilchee / weatherman.py
Last active February 10, 2017 04:46
Get Current Conditions by Zip Code. You need an openweathermap api key.
#!/usr/bin/env python3
import requests
import sys
from configparser import ConfigParser
class WeatherAPI:
def get_current_conditions(zip_code):
# Try and read in api key from default config
try:
@gnilchee
gnilchee / comprehension.py
Created January 24, 2017 03:52
dict and list comprehension in python
#!/usr/bin/env python3
# my reference list
nums = [1,2,3,4,5,6,7,8,9,10]
# 'n' for each 'n' in nums list
my_list = []
for n in nums:
my_list.append(n)
print(my_list)
@gnilchee
gnilchee / employee.py
Created January 12, 2017 02:45
Simple Practice of class use and multi-line formatting return string
#!/usr/bin/env python3
class Employee:
def __init__(self, first_name, last_name, salary, position):
self.first_name = first_name
self.last_name = last_name
self.salary = salary
self.position = position
self.email = first_name + '.' + last_name + '@div.company.com'
@gnilchee
gnilchee / go_github_rate_limit.go
Last active January 9, 2017 06:23
Using net/http and json encoding to pull out nested json values and stored into map
package main
import (
"fmt"
"log"
"net/http"
"io/ioutil"
"encoding/json"
)
@gnilchee
gnilchee / func_mult_response.go
Created January 9, 2017 02:28
Simple function with multiple input (and types) and multiple returns (and types)
package main
import "fmt"
func add(x int, y int, greet string) (integer int, res string) {
sum := x + y
response := greet + ", World"
return sum, response
}
@gnilchee
gnilchee / get_github_api.go
Created January 7, 2017 05:43
Using json and net/http get, parse and select data from web endpoint response.
package main
import (
"fmt"
"log"
"net/http"
"io/ioutil"
"encoding/json"
)
@gnilchee
gnilchee / get_request_url.go
Created January 4, 2017 07:01
Get content and status code of headers and body and print to screen. Url is pulled from commandline arguments
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
)