Skip to content

Instantly share code, notes, and snippets.

@ikai
ikai / 0_reuse_code.js
Created September 27, 2016 19:04
Here are some things you can do with Gists in GistBox.
// 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 November 19, 2015 01:37
Simplest boto3 example for creating an RDS PostgreSQL instance
import time
import boto3
import botocore
def main():
db_identifier = 'yourDBID'
rds = boto3.client('rds')
try:
@ikai
ikai / slack_example.py
Created October 7, 2015 18:51
Actual working slack example code
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 August 6, 2015 20:13
Shows how to print the exact string subprocess is using from a list
cmd_args = ['cat', 'somefile.txt']
print subprocess.list2cmdline(cmd_args)
$ 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 February 9, 2017 04:07
Search by keyword sample for the YouTube API for Google Apps Script.
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);
}
}
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 July 1, 2013 22:12
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.
#!/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 June 10, 2013 23:54
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.
buildscript {
repositories {
maven {
url 'http://repo1.maven.org/maven2'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
@ikai
ikai / ImageFetcher.java
Created March 30, 2013 21:31
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 …
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;