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 predict_stats(a_stats, i_days): | |
x = np.array( list(range(0,len(a_stats))) ) | |
y = np.array(a_stats) | |
z = np.polyfit(x,y,3) # construct x**2 + xy + 3 | |
p_true = np.poly1d(z) | |
return p_true(len(a_stats) + i_days) |
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 | |
# Given an array of integers, return indices of the two nums such that they add up to a specific target. | |
# | |
# You may assume that each input would have exactly one solution, and you may not use the same element twice. | |
def two_sum(nums, target) | |
a_copy = [] |
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
/*********************************************************************** | |
* connect.c -- Make socket connection using SOCKS4/5 and HTTP tunnel. | |
* | |
* Copyright (c) 2000-2004 Shun-ichi Goto | |
* Copyright (c) 2002, J. Grant (English Corrections) | |
* | |
* This program is free software; you can redistribute it and/or | |
* modify it under the terms of the GNU General Public License | |
* as published by the Free Software Foundation; either version 2 | |
* of the License, or (at your option) any later version. |
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
<?php | |
function h($string, $esc_type = 'htmlall') | |
{ | |
switch ($esc_type) { | |
case 'css': | |
$string = str_replace(array('<', '>', '\\'), array('<', '>', '/'), $string); | |
// get rid of various versions of javascript | |
$string = preg_replace( | |
'/j\s*[\\\]*\s*a\s*[\\\]*\s*v\s*[\\\]*\s*a\s*[\\\]*\s*s\s*[\\\]*\s*c\s*[\\\]*\s*r\s*[\\\]*\s*i\s*[\\\]*\s*p\s*[\\\]*\s*t\s*[\\\]*\s*:/i', |
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 | |
require 'rubygems' | |
require 'rmagick' | |
def is_grayscale(file_name) | |
Magick::Image.read('trix_pushed_2_stops.jpg')[0].each_pixel do |pixel, col, row| | |
puts "Pixel at: #{col}x#{row}:\tR: #{pixel.red}, G: #{pixel.green}, B: #{pixel.blue}" | |
unless (pixel.red == pixel.green) && (pixel.green == pixel.blue) | |
return FALSE |
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
from amazonadapi import AmazonClient | |
import os | |
client = AmazonClient() | |
client.refresh_token = os.environ['AMZN_REFRESH_TOKEN'] | |
client.auto_refresh_token() | |
client.set_region() | |
client.profile_id = '3586026682031981' | |
orders = client.get_orders(dsp_advertiser_id) | |
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 collections | |
c = collections.Counter('helloworld') | |
print(c) | |
# Counter({'l': 3, 'o': 2, 'e': 1, 'd': 1, 'h': 1, 'r': 1, 'w': 1}) | |
print(c.most_common(3)) | |
# [('l', 3), ('o', 2), ('e', 1)] |
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 dispatch_if(operator, x, y): | |
if operator == 'add': | |
return x + y | |
elif operator == 'sub': | |
return x - y | |
elif operator == 'mul': | |
return x * y | |
elif operator == 'div': | |
return x / y | |
else: |
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 'rest_client' | |
require 'json' | |
# RestClient.log=STDOUT # Optionally turn on logging | |
q = '{ | |
"query" : { "term" : { "user" : "kimchy" } } | |
} | |
' | |
r = JSON.parse \ |
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 'faraday' | |
conn = Faraday.new(:url => 'https://www.google.com') do |faraday| | |
faraday.request :url_encoded # form-encode POST params | |
faraday.response :logger # log requests to STDOUT | |
faraday.adapter Faraday.default_adapter # make requests with Net::HTTP | |
end | |
response = conn.get '/' |
NewerOlder