Skip to content

Instantly share code, notes, and snippets.

Barce barce

Block or report user

Report or block barce

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@barce
barce / twosum.rb
Created Jun 14, 2019
leetcode problem
View twosum.rb
#!/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 = []
@barce
barce / connect.c
Created Oct 3, 2018
used for creating a (privoxy and/or tor) and ssh proxy
View connect.c
/***********************************************************************
* 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.
View killXSS.php
<?php
function h($string, $esc_type = 'htmlall')
{
switch ($esc_type) {
case 'css':
$string = str_replace(array('<', '>', '\\'), array('&lt;', '&gt;', '&#47;'), $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',
@barce
barce / naive_grayscale.rb
Last active May 4, 2018
Naively check is an image is a grayscale image (very slow)
View naive_grayscale.rb
#!/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
@barce
barce / amazonadapi_example.py
Created Nov 27, 2017
example of using Amazon AD API
View amazonadapi_example.py
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)
@barce
barce / collections.py
Last active Jun 19, 2017
collections in python
View collections.py
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)]
@barce
barce / dict as a switch in python
Created May 25, 2017
Using a dict as a switch in Python
View dict as a switch in python
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:
View json_get.rb
require 'rest_client'
require 'json'
# RestClient.log=STDOUT # Optionally turn on logging
q = '{
"query" : { "term" : { "user" : "kimchy" } }
}
'
r = JSON.parse \
@barce
barce / faraday_test.rb
Created Jun 8, 2015
test if faraday is working
View faraday_test.rb
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 '/'
View fibo.js
function fibonacci(n) {
return n<2?n:fibonacci(n-1)+fibonacci(n-2);
}
var fibonacciSeries = function(fibonacciLimit) {
var result = Array();
var currentFibonacciValue = fibonacci(0);
var i = 1;
while (currentFibonacciValue < fibonacciLimit) {
result.push(currentFibonacciValue);
You can’t perform that action at this time.