Skip to content

Instantly share code, notes, and snippets.

@ikai
ikai / 0_reuse_code.js
Created Sep 27, 2016
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@ikai
ikai / boto3_rds_example.py
Created Nov 19, 2015
Simplest boto3 example for creating an RDS PostgreSQL instance
View boto3_rds_example.py
import time
import boto3
import botocore
def main():
db_identifier = 'yourDBID'
rds = boto3.client('rds')
try:
@ikai
ikai / slack_example.py
Created Oct 7, 2015
Actual working slack example code
View slack_example.py
from slackclient import SlackClient
# Don't prefix the #
channel_name = 'apitest'
# Your API key is actually found at https://api.slack.com/web
token = 'your API key'
sc = SlackClient(token)
sc.rtm_connect()
@ikai
ikai / subprocess_cmd_args.py
Created Aug 6, 2015
Shows how to print the exact string subprocess is using from a list
View subprocess_cmd_args.py
cmd_args = ['cat', 'somefile.txt']
print subprocess.list2cmdline(cmd_args)
View gist:f5a53870442adfe1acd9
$ whois getcoupons.pw
Domain ID:CNIC-DO2751397
Domain Name:GETCOUPONS.PW
Created On:2014-05-20T18:54:45.0Z
Last Updated On:2014-05-25T18:57:08.0Z
Expiration Date:2015-05-20T23:59:59.0Z
Status:clientTransferProhibited
Status:serverTransferProhibited
Registrant ID:L24FVEUTOVCIHDJM
Registrant Name:WhoisGuard Protected
@ikai
ikai / searchByKeyword.gs
Last active Feb 9, 2017
Search by keyword sample for the YouTube API for Google Apps Script.
View searchByKeyword.gs
function searchByKeyword() {
var results = YouTube.Search.list("id,snippet",
{q : "google apps script", maxResults: 25});
for(var i in results.items) {
var item = results.items[i];
Logger.log("[%s] Title: %s", item.id.videoId, item.snippet.title);
}
}
View Catching GoogleJsonResponseException
try {
// Make your Google API call
} catch (GoogleJsonResponseException e) {
GoogleJsonError error = e.getDetails();
// Print out the message and errors
}
@ikai
ikai / generate_token.py
Created Jul 1, 2013
Very simple Python sample to generate a refresh token for the YouTube API. Note that this will will also create a file called generate_token.py-oauth that contains this information.
View generate_token.py
#!/usr/bin/python
import httplib2
import os
import sys
from apiclient.discovery import build
from oauth2client.file import Storage
from oauth2client.client import flow_from_clientsecrets
from oauth2client.tools import run
@ikai
ikai / build.gradle
Created Jun 10, 2013
TIL: to get Gradle to use external Maven dependencies, you need to declare repositories OUTSIDE 'buildscript'. If you don't, you get an error telling you Gradle can't resolve whatever external dependencies your project depend on.
View build.gradle
buildscript {
repositories {
maven {
url 'http://repo1.maven.org/maven2'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
@ikai
ikai / ImageFetcher.java
Created Mar 30, 2013
A tool I've used a few times in various Android samples. I've simplified and greatly generalized this from some code I helped write for a friend. This class helps fetch lots of images in a background thread pool, executing a callback on a main thread when complete. This code caches the images locally, opting to fetch first from the cache before …
View ImageFetcher.java
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.security.MessageDigest;