Skip to content

Instantly share code, notes, and snippets.

@sang4lv
sang4lv / gist:4461076
Created January 5, 2013 11:16
applicationCache: Overview
var appCache = window.applicationCache;
//Update when ready
appCache.onupdateready = function() {
if(appCache.status == 'UPDATEREADY') {
appCache.swapCache();
if(confirm("New content available. Reload to show?")) {
window.location.reload();
}
}
@sang4lv
sang4lv / gist:4466191
Created January 6, 2013 09:03
Express Error
Angelas-Mac:~ angelazou$ sudo npm install -g [email protected]
Password:
npm http GET https://registry.npmjs.org/express/2.5.8
npm http 200 https://registry.npmjs.org/express/2.5.8
npm http GET https://registry.npmjs.org/express/-/express-2.5.8.tgz
npm http 200 https://registry.npmjs.org/express/-/express-2.5.8.tgz
npm WARN engine [email protected]: wanted: {"node":">= 0.4.1 < 0.7.0"} (current: {"node":"v0.8.16","npm":"1.1.69"})
npm http GET https://registry.npmjs.org/connect
npm http GET https://registry.npmjs.org/mime/1.2.4
npm http GET https://registry.npmjs.org/qs
@sang4lv
sang4lv / gist:4466296
Created January 6, 2013 09:38
Express Error Using Latest Version
Angelas-Mac:~ angelazou$ sudo npm install -g express@latest
Password:
npm http GET https://registry.npmjs.org/express
npm http 200 https://registry.npmjs.org/express
npm http GET https://registry.npmjs.org/express/-/express-3.0.6.tgz
npm http 200 https://registry.npmjs.org/express/-/express-3.0.6.tgz
npm http GET https://registry.npmjs.org/range-parser/0.0.4
npm http GET https://registry.npmjs.org/mkdirp/0.3.3
npm http GET https://registry.npmjs.org/cookie/0.0.5
npm http GET https://registry.npmjs.org/buffer-crc32/0.1.1
@sang4lv
sang4lv / gist:4499788
Created January 10, 2013 05:58
MySQLi example
<?php
function processURL($originalURL, $array) {
$base = "http://example.com";
$avail = "";
$link = new mysqli($host, $user, $pass, $daba);
if(mysqli_connect_errno()) {
die("Connection failed" . mysqli_connect_error());
}
@sang4lv
sang4lv / gist:4500115
Created January 10, 2013 07:05
Error 500 with following rewrite rules
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite PHP" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" negate="true" pattern="(.*).php" />
</conditions>
@sang4lv
sang4lv / gist:4511439
Created January 11, 2013 15:20
Windows Azure MySQL database connection using PHP
<?php
echo xiaoxiaoURL($_GET['url']);
function xiaoxiaoURL($url) {
$base64 = array(
'q', 'w', 'e', 'r', 't', 'y', 'u', 'i',
'o', 'p', 'a', 's', 'd', 'f', 'g', 'h',
'j', 'k', 'l', 'z', 'x', 'c', 'v', 'b',
'n', 'm', '0', '9', '8', '7', '6', '5'
);
@sang4lv
sang4lv / gist:4528499
Last active December 11, 2015 02:09
Edu About Draft
Edu is a platform to teach and learn content. We focus on enhancing the teaching style to help students learn better. We have virtual classrooms that are set up to allow students to ask questions directly and more intimately. We have blackboard drawing video to help systems to do more than just powerpoint presentation, but reach out to students in a more friendly way.
Students can go through various kinds of tests such as flash cards or quizzes to earn credit for their learning style. and they can also give feedback to teachers about improving their teaching style.
Best of all, we are build to extend. Different courses have different demands because they target to teach different content, we can provide an open source platform and framework for other developers to extend the platform by building new plugins to fit their need.
Important and Urgent
- Interface Design
- Database Connection
@sang4lv
sang4lv / flush.php
Last active December 17, 2015 07:39
CPT Rewrite Flush
<?php
add_action( 'registered_post_type', 't5_silent_flush_cpt', 10, 2 );
add_action( 'registered_taxonomy', 't5_silent_flush_tax', 10, 3 );
/**
* Flush rules for custom post types.
*
* @wp-hook registered_post_type
* @param string $post_type
* @param stdClass $args
@sang4lv
sang4lv / gist:5590092
Created May 16, 2013 07:48
Unsetting array memory
<?php
$init = memory_get_usage();
$time = microtime();
echo "method 1 (unset): " . $init . "<br />";
$array = array();
for($i = 0; $i < 1000; $i += 1) {
$array[] = 'string';
}
echo "after setup: " . memory_get_usage() . "<br />";
unset($array);
@sang4lv
sang4lv / gist:5648943
Last active December 17, 2015 17:49
Node File Write
//Which is the better way? Perform FS read during response.write or independently?
//Read during response write
response.write(function() {
fs.readFile('./index.html', function (error, html) {
if (error) {
throw error;
} else {
return html;
}
});