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 re | |
regex_url = re.compile("^(?:(?P<scheme>https?|ftps?):\/\/)?(?:(?:(?P<username>[\w\.\-\+%!$&'\(\)*\+,;=]+):*(?P<password>[\w\.\-\+%!$&'\(\)*\+,;=]+))@)?(?P<host>[a-z0-9-]+(?:\.[a-z0-9-]+)*(?:\.[a-z\.]{2,6})+)(?:\:(?P<port>[0-9]+))?(?P<path>\/(?:[\w_ \/\-\.~%!\$&\'\(\)\*\+,;=:@]+)?)?(?:\?(?P<query>[\w_ \-\.~%!\$&\'\(\)\*\+,;=:@\/]*))?(?:(?P<fragment>#[\w_ \-\.~%!\$&\'\(\)\*\+,;=:@\/]*))?$", re.IGNORECASE) | |
example_url = "http://username:[email protected]:130892/some/path/to/folder?query1=1&query2=2#go-to-fragment" | |
match_test = re.match(regex_url, example_url) | |
if match_test: | |
print match_test.groupdict() |
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 re | |
import urllib | |
import httplib | |
import mimetypes | |
import os | |
regex_url = re.compile("^(?:(?P<scheme>http|ftps?):\/\/)?(?:(?:(?P<username>[\w\.\-\+%!$&'\(\)*\+,;=]+):*(?P<password>[\w\.\-\+%!$&'\(\)*\+,;=]+))@)?(?P<host>[a-z0-9-]+(?:\.[a-z0-9-]+)*(?:\.[a-z\.]{2,6})+)(?:\:(?P<port>[0-9]+))?(?P<path>\/(?:[\w_ \/\-\.~%!\$&\'\(\)\*\+,;=:@]+)?)?(?:\?(?P<query>[\w_ \-\.~%!\$&\'\(\)\*\+,;=:@\/]*))?(?:(?P<fragment>#[\w_ \-\.~%!\$&\'\(\)\*\+,;=:@\/]*))?$") | |
def parse_url(url): | |
match = re.match(regex_url, url, re.IGNORECASE) |
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
package main | |
import ( | |
"http" | |
"io/ioutil" | |
"fmt" | |
"os" | |
) | |
//var ( |
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 python | |
def radix_sort(random_list): | |
len_random_list = len(random_list) | |
modulus = 10 | |
div = 1 | |
while True: | |
# empty array, [[] for i in range(10)] | |
new_list = [[], [], [], [], [], [], [], [], [], []] | |
for value in random_list: |
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
db.test.insert({'name': 'rizky', 'abilities': ['eat', 'sleep', 'code']}); | |
db.test.insert({'name': 'abdilah', 'abilities': ['drink']}); | |
db.test.insert({'name': 'median', 'abilities': null}); | |
condition_have_ability_more_than_2 = function(){ | |
return typeof(this.abilities) == "object" && this.abilities != null && this.abilities.length > 2; | |
} | |
// peoples have abilities more_than_2 | |
db.test.find(condition_have_ability_more_than_2); |
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
# add last 3 line in line 150 file setup.py | |
add_directory(library_dirs, "/lib64") | |
add_directory(library_dirs, "/usr/lib64") | |
add_directory(library_dirs, "/usr/lib/x86_64-linux-gnu") |
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
# example nested if, in real life it will be uglier | |
if a: | |
# do some code with a | |
if b: | |
# do some code with a and b | |
if c: | |
# do some code with a, b and c | |
else: | |
print "you must set b" | |
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
arrayIntersect_ = (arg1, arg2) -> | |
retVal = [] | |
hashMap = {} | |
for l in arg1 | |
hashMap[l] = 1 | |
for l in arg2 | |
if hashMap[l] and ((hashMap[l] += 1) == 2) | |
retVal.push(l) |
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
#!/opt/python/bin/python | |
from bottle import BaseTemplate | |
class ExampleGlobal(object): | |
name = "Hello World" | |
gob = ExampleGlobal() | |
BaseTemplate.global_config('jinja2_global_env', {'gob': gob}) | |
## do with your creativity |
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
#!/opt/python/bin/python | |
class Jinja2Template(BaseTemplate): | |
global_env = None | |
def prepare(self, filters=None, tests=None, **kwargs): | |
from jinja2 import Environment, FunctionLoader | |
if 'prefix' in kwargs: # TODO: to be removed after a while | |
raise RuntimeError('The keyword argument `prefix` has been removed. ' | |
'Use the full jinja2 environment name line_statement_prefix instead.') | |
self.env = Environment(loader=FunctionLoader(self.loader), **kwargs) |
OlderNewer