Skip to content

Instantly share code, notes, and snippets.

View shuson's full-sized avatar
🎯
Focusing

Nevermoi shuson

🎯
Focusing
View GitHub Profile
@shuson
shuson / andor.py
Created June 25, 2013 09:56
For those who are familiar with "? :" in C, but "and or" usage in python is a little different.
a = 'a'
b = 'b'
print True and a or b
# output is 'a'
c = '' #bool(c) is False
d = 'd'
print True and c or d
#output is 'd'
@shuson
shuson / Drupal7 Installation
Last active December 20, 2015 01:19
Drupal7 Installation (Ubuntu12.04) from the very beginning.
Step 1: LAMP installation guide
take a tour to this link http://www.howtoforge.com/ubuntu_lamp_for_newbies
(Don't forget to Include /etc/phpmyadmin/apache.conf to the apache2.conf file)
after those, apache2,php5,mysql and phpmyadmin are done. Type in localhost/phpmyadmin to check whether everything is ok.
Step 2: Download Drupal7 and Extract it to /home/xxx/www and Create new site in apache2
in 'terminal'
cd /etc/apache2/sites-available
sudo cp default drupal7
sudo nano drupal7 #here change DocumentRoot /var/www to /home/xxx/www # I download drupal and extract to /home/xxx/www
#change <Directory /var/www to /home/xxx/www and save
@shuson
shuson / coprime_checker.py
Created July 21, 2013 13:28
By reading RSA algorithm,to generate a series co-prime relation numbers is the basic task. So comes out of this basic method
#if the return is 1, the a b are in coprime relation
#else return the smallest common divisor
def checker(a,b):
while True:
c = a%b
if c == 0:
return b
a = b
b = c
@shuson
shuson / app.py
Last active January 4, 2016 19:08
make flask and nginx allow cross domain ajax requests from angularjs
from flask import Flask
from flask import jsonify
from crossdomain import *
app = Flask(__name__)
@app.route("/user")
@crossdomain(origin='*')
def getuser():
return jsonify({'name': "aaa", "age": 11})
@shuson
shuson / copy.md
Created March 18, 2014 09:59 — forked from tiye/copy.md

和大家分享一下我整理的有趣的Github repository,项目地址在repo_starred

欢迎大家fork或者给我发issue

部分内容如下,不定期更新:

GitHub Starred Projects

##navigation

#!/usr/bin/python
# Quick and dirty demonstration of CVE-2014-0160 by Jared Stafford (jspenguin@jspenguin.org)
# The author disclaims copyright to this source code.
import sys
import struct
import socket
import time
import select
@shuson
shuson / description-mysql_weakly-referenced object
Last active April 26, 2024 13:04
weakly-referenced object when connect to mysql in python
I came across this issue using the following code file
the error message is ReferenceError: weakly-referenced object no longer exists
reason is in the mysql/connector/cursor.py file
see these lines:
def _set_connection(self, connection):
"""Set the connection"""
try:
@shuson
shuson / Trader.java
Created June 19, 2014 08:29
Merchant's Guide To The Galaxy Solution
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
@shuson
shuson / DatetimeDiffWithFormat
Created July 18, 2014 08:01
Calculate Datetime difference with output in this format "xx year(s) xx month(s) xx day(s)"
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.Duration;
import org.joda.time.Period;
class DatetimeDiffWithFormat{
/**
* @param DateTime start
* @param DateTime end
* @param UnitDMYENUM unit
@shuson
shuson / kmp_alg
Created October 29, 2014 08:16
The KMP Algorithm implementation in Python
def buildPMT(s):
"""
PartialMatchTable of string s
"""
prefix = [s[:i+1] for i in range(len(s)-1)]
postfix = [s[i+1:] for i in range(len(s)-1)]
intersection = list(set(prefix) & set(postfix))
if intersection:
return len(intersection[0])
return 0