Skip to content

Instantly share code, notes, and snippets.

View jesuscast's full-sized avatar

Andres Castaneda jesuscast

View GitHub Profile
@jesuscast
jesuscast / permutations_exhaustive.py
Last active November 27, 2015 00:45
Exhaustive search algorithm that given a list of numbers L tries to find the set M of L with the least cardinality (lowest number of elements) that when added together the result lies within a percent error C of a goal number G, according to the following inequality: (C-1)*G < Sigma(M) < (C+1)*G
def r(m, g, l, d, u, j):
# print "r iteration: "+str(d)
if d == len(l)+10:
return False
mS = sum(m)
mL = len(m)
if mS == g:
return m
if mS < g*(1.0+j) and mS > g*(1.0-j):
return m
@jesuscast
jesuscast / lol.js
Created December 3, 2015 23:28
hides deleted ads from your craigslist account.
$(".status").each(function(index, element) { if($(element).html().indexOf("Deleted") != -1 ) { $(element).parent().hide(); }; });
@jesuscast
jesuscast / david.py
Last active February 16, 2016 18:57
# First initialize the array with all positions 0
array_2d = None
calculated_values = None
# save the total number of rows and the total number of columns in global variables
rows_n = 0
columns_n = 0
testing = False
# Now make the function to obtain the values at y_row, and x_column
@jesuscast
jesuscast / maxer.sh
Created March 18, 2016 06:11
Finds the id of the process that has the most open files.
HIGHEST_PROCESS=''
HIGHEST_PROCESS_FILES=0
ps aux | awk 'NR > 1' | awk '{ print $2 }' > tmp.txt
while read -r process_element; do
process_pid="$process_element"
number_of_files=`lsof -p $process_pid | wc -l | awk '{ print $1 }'`
if [ $number_of_files -gt $HIGHEST_PROCESS_FILES ]; then
HIGHEST_PROCESS=$process_pid
HIGHEST_PROCESS_FILES=$number_of_files
fi
function sendTextMessage(sender, text) {
let messageData = { text:text }
request({
url: 'https://graph.facebook.com/v2.6/me/messages',
qs: {access_token:token},
method: 'POST',
json: {
recipient: {id:sender},
message: messageData,
var chromeCapabilities, chromeOptions, driver;
chromeCapabilities = selenium.Capabilities.chrome();
chromeOptions = {
'args': ['--load-extension=yourExtensionFolder']
};
chromeCapabilities.set('chromeOptions', chromeOptions);
driver = new selenium.Builder().usingServer('http://x.x.x.x:4444/wd/hub').withCapabilities(chromeCapabilities).build();
driver.getWindowHandle();
java -jar selenium-server-standalone.jar -role node -hub http://localhost:4444/grid/register -browser browserName=chrome,version=52.0,chrome_binary='/usr/bin/google-chrome',platform=LINUX,maxInstances=5
def binarySearch(alist, item):
first = 0
last = len(alist)-1
index = None
while first<=last and not index:
midpoint = (first + last)//2
if alist[midpoint] >= item:
index = midpoint
else:
if item < alist[midpoint]:
def binarySearch(alist, item):
first = 0
last = len(alist)-1
index = None
while first<=last and not index:
midpoint = (first + last)//2
if alist[midpoint] >= item:
index = midpoint
else:
if item < alist[midpoint]:

Implement a REST server with the following endpoints.

POST /user/register

Body

{
  "username": "XXXXXXX”
}