Skip to content

Instantly share code, notes, and snippets.

View qsun's full-sized avatar
🎯
Focusing

Quan qsun

🎯
Focusing
  • open
  • Sydney NSW Australia
View GitHub Profile
(defun solve-helper (primes candidates)
(let ((first-number (car candidates)))
(if first-number
(solve-helper (cons first-number primes)
(remove-if #'(lambda (n)
(declare (integer n))
(= 0 (mod n first-number)))
(cdr candidates)))
primes)))
@qsun
qsun / lisp
Created October 18, 2010 12:38
facebook javascript login dirty check
(defparameter *facebook-app-id* "id")
(defparameter *facebook-app-secret* "secret")
(defun facebook-login-p ()
(let ((kvs (sort (map 'list (lambda (kv)
(split-sequence:split-sequence #\= kv))
(split-sequence:split-sequence #\& (string-trim (list #\") (hunchentoot:cookie-in (format nil "fb
@qsun
qsun / gist:762980
Created January 3, 2011 00:50
remove BOM (byte order mark) FEFF
#!/bin/sh
MD5=md5
function usage()
{
echo bom_removal.sh file
}
function remove_bom
<?php
/* license - GPL */
/* this function will extract terms from the text, by Yahoo Query Language's search.termextract API */
function extract_terms($content) {
$query = "SELECT * FROM search.termextract WHERE context = '" . str_replace("'", "", $content) . "'";
$query_url = 'http://query.yahooapis.com/v1/public/yql?q=' . urlencode($query) . '&format=json';
@qsun
qsun / gist:1247402
Created September 28, 2011 08:49
ruby integer to/from ip address
require 'ipaddr'
IPAddr.new('1.2.3.4').to_i
IPAddr.new(16909060, Socket::AF_INET).to_s
@qsun
qsun / gist:1341320
Created November 5, 2011 09:37
Remove the continuous spaces before and after current point
(defun consolidate-spaces ()
"Remove the continuous spaces before and after current point"
(interactive)
(let (start end)
(skip-chars-backward "[:space:]")
(setq start (point))
(skip-chars-forward "[:space:]")
(setq end (point))
(delete-region start end)))
@qsun
qsun / gist:1357582
Created November 11, 2011 09:22
Real Time Referrer Indexing
<?php
//////////////////////////////
// Referreral Builder 1.0
// Copyright 2011, Russ Jones, Virante, Inc.
///////////////////////////////
// Assumes you create a table called
// ref_slots with 3 fields, url and ref, each varchar(255) and status, tinyint, REF should be primary key
$dbh = mysql_connect("localhost","username","password");
@qsun
qsun / raise skeles before pindleskin.js
Created December 26, 2011 02:12
Raise skeles before fighting with pindleskin. Use this function to replace original one in NTPindleskin.ntj
function NTMain()
{
Include("libs/common/NTCommon.ntl");
NTC_IncludeLibs();
NTC_IncludeConfig("NTBot/char_configs");
NT_LoadConfig();
NTSI_LoadNIPFiles("NTBot/item_configs");
NTA_Initialize();
@qsun
qsun / executeSQL.php
Created January 8, 2012 21:16
Easier PDO
public function executeSQL($dbh, $sql, $params = array()) {
try {
$stmt = $dbh->prepare($sql); //Used by all query types.
if (substr($sql, 0, 6) === "SELECT") {
//Select
$stmt->execute($params);
return $stmt->fetchAll(PDO::FETCH_ASSOC); //Returns an Array if data returned. Use is_array to check.
} else {
//Create/Insert/Update/Delete/Drop
@qsun
qsun / indexed.php
Created January 21, 2012 23:00
Check if URL is indexed by Google
<?php
function indexed($url) {
$url = 'http://webcache.googleusercontent.com/search?q=cache:' . urlencode($url);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Chrome 10');