Skip to content

Instantly share code, notes, and snippets.

View SFantasy's full-sized avatar
🌝
ENJOY~

Fantasy SFantasy

🌝
ENJOY~
View GitHub Profile
@SFantasy
SFantasy / sudoku.pro
Last active December 10, 2015 02:58
I learned it from the book 'Seven languages in seven weeks', it is so fun solving Sudoku using Prolog! 一种用来快速解决Sudoku的编程方式--逻辑编程,Programming Logically! 如果用来解决6*6或者9*9的Sudoku,更改构造的Puzzle即可。
/*验证该列表中没有重复的数字*/
valid([]).
valid([Head|Tail]) :-
fd_all_different(Head),
valid(Tail).
/*构造Puzzle*/
sudoku(Puzzle, Solution) :-
Solution = Puzzle,
Puzzle = [S11, S12, S13, S14,
@SFantasy
SFantasy / mergeFile.py
Created December 26, 2012 13:37
合并两个文件,如:将test1.txt中的所有行添加到test2.txt的每个行的最末尾。
#/usr/bin/python
#Filename: mergeFile.py
#Usage: merge all the lines in test1 and test2
file1 = open('test1.txt', 'r')
file2 = open('test2.txt', 'r')
lines1 = file1.readlines()
lines2 = file2.readlines()
@SFantasy
SFantasy / getClass.js
Last active December 17, 2015 00:29
My implementation of `getElementsByClass()`
function getClass(c) {
var l = document.getElementsByTagName('*');
var x = new Array();
for(var i = 0; i < l.length; i++) {
if(l[i].classList !== undefined && l[i].classList.contains(c)) {
x.push(l[i]);
}
}
@SFantasy
SFantasy / jsonexample.json
Created May 25, 2013 17:23
JSON syntax example.
{
"name": "Medivh",
"age": 18,
"location": "Azeroth",
"hobby": [ "eating","sleeping" ],
"friends": [
{
"name": "Lothar",
"age": 21,
"profession": "solider"
@SFantasy
SFantasy / getTime.html
Created May 25, 2013 17:52
JavaScript实时获取时间
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Clock</title>
<script>
var i;
function getTime () {
var date = new Date();
var year = date.getFullYear();
/* Template part from twitter.github.io/bootstrap
*
*/
body {
color: #777;
background-color: #f1f1f1;
font-family: "Microsoft YaHei", Georgia, 黑体, Helvetica, Arial, sans-serif;
padding-top: 20px;
}
@SFantasy
SFantasy / animation-rotate.html
Created August 1, 2013 09:33
CSS animation example
<!DOCTYPE html>
<html>
<head>
<title></title>
<style>
.row > a#transform {
text-decoration: none;
width: 40px;
height: 40px;
display: inline-block;
@SFantasy
SFantasy / ajax.js
Last active December 22, 2015 00:19
Simple Ajax wrapped.
var Ajax = {
/**
* ajax 封装
* @param options {
* type: GET || POST
* datatype: JSON as default
* url: Interface URL
* sdata:
* callback: Callback function
* async: true || false
@SFantasy
SFantasy / index.html
Created October 28, 2013 05:58
HTML template
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="keywords" content="type your keywords here" />
<meta name="description" content="type your description here" />
<meta id="viewport" name="viewport"
content="widht=device-width, user-scalable=yes, initial-scale=0.5" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta content="black" name="apple-mobile-web-app-status-bar-style" />
<!DOCTYPE html>
<html ng-app>
<head>
<meta name="description" content="first AngularJS application" />
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<div ng-controller='TestController'>