This file contains hidden or 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
using System; | |
using System.Text; | |
using System.Security.Cryptography; | |
static class Hash | |
{ | |
public static string SHA1(string text) | |
{ | |
byte[] buffer = Encoding.UTF8.GetBytes(text); | |
var sha1 = new SHA1CryptoServiceProvider(); |
This file contains hidden or 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 django.db import models | |
class TimeStampedModel(models.Model): | |
""" | |
An abstract base class model that provides self-updating 'created' | |
and 'modified' fields. | |
""" | |
created = models.DateTimeField(auto_now_add=True) | |
modified = models.DateTimeField(auto_now=True) |
This file contains hidden or 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
# A list of possible reserved words | |
reserved_words = [ | |
# Companies | |
'amazon', 'apple', 'atlassian', 'canonical', 'facebook', 'github', | |
'google', 'htc', 'huawei', 'ibm', 'microsoft', 'mozilla', 'naughtydog', | |
'nintendo', 'nokia', 'rim', 'samsung', 'sony', 'toshiba', 'twitter', | |
'ubisoft', 'wikipedia', 'xref', 'yahoo', | |
# Operating systems |
This file contains hidden or 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 | |
/** | |
* Find difference between two dates in days. PHP 5.2.x. | |
*/ | |
$d1 = date('Y-m-d', strtotime('2013-06-13 12:27:43')); | |
$d2 = date("Y-m-d"); | |
echo diff($d1, $d2); | |
function diff($date1, $date2) { |
This file contains hidden or 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 | |
$http_client_ip = ''; | |
$http_x_forwarded_for = ''; | |
$remote_addr = $_SERVER['REMOTE_ADDR']; | |
$remote_host = ''; | |
$remote_port = $_SERVER['REMOTE_PORT']; | |
$remote_user = ''; | |
$redirect_remote_user = ''; | |
$http_user_agent = $_SERVER['HTTP_USER_AGENT']; |
This file contains hidden or 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 | |
import os, sys | |
import hashlib | |
def usage(full=False): | |
msg = '' | |
if full: | |
msg += 'Computes hash of a string.' + os.linesep |
This file contains hidden or 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 | |
try { | |
$options = array( | |
'soap_version'=>SOAP_1_2, | |
'exceptions'=>true, | |
'trace'=>1, | |
'cache_wsdl'=>WSDL_CACHE_NONE | |
); | |
$client = new SoapClient('http://soap.service-provider.com/endpoint.asmx?WSDL', $options); | |
} |
This file contains hidden or 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 sum(args): | |
""" Returns sum of all elements of a given list, recursively """ | |
if len(args) == 0: | |
return 0 | |
return args[0] + sum(args[1:]) | |
if __name__ == "__main__": |
This file contains hidden or 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 | |
units = { | |
0: 'Zero', 1: 'One', 2: 'Two', 3: 'Three', 4: 'Four', 5: 'Five', 6: 'Six', 7: 'Seven', 8: 'Eight', 9: 'Nine' | |
} | |
tens = { | |
10: 'Ten', 11: 'Eleven', 12: 'Twelve', 13: 'Thirteen', 14: 'Fourteen', 15: 'Fifteen', 16: 'Sixteen', | |
17: 'Seventeen', 18: 'Eighteen', 19: 'Nineteen', 20: 'Twenty', 30: 'Thirty', 40: 'Forty', 50: 'Fifty', | |
60: 'Sixty', 70: 'Seventy', 80: 'Eighty', 90: 'Ninety' | |
} |
This file contains hidden or 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 ugly_number(n): | |
""" Returns Nth ugly number """ | |
assert n > 0, 'The argument must be greater than zero.' | |
list = [0]*n | |
i2, i3, i5 = 0, 0, 0 | |
w2, w3, w5 = 2, 3, 5 | |
w, list[0] = 1, 1 | |
OlderNewer