Skip to content

Instantly share code, notes, and snippets.

View skwi's full-sized avatar
👥
N1que les clones

Cédric skwi

👥
N1que les clones
View GitHub Profile
@skwi
skwi / detect-orientation.js
Created April 11, 2012 09:19
Detect Orientation Change in Javascript
window.addEventListener("orientationchange", function() {
// Announce the new orientation number
alert(window.orientation);
}, false);
@skwi
skwi / preload.js
Created April 11, 2012 09:24
Preload images with jQuery
$function($) {
var cache = [];
// Arguments are image paths relative to the current page.
$.preLoadImages = function() {
var args_len = arguments.length;
for (var i = args_len; i--;) {
var cacheImage = document.createElement('img');
cacheImage.src = arguments[i];
cache.push(cacheImage);
}
@skwi
skwi / gist:2405905
Created April 17, 2012 13:14
Make Slug
function slug($str)
{
$str = strtolower(trim($str));
$str = preg_replace('/[^a-z0-9-]/', '-', $str);
$str = preg_replace('/-+/', "-", $str);
return $str;
}
@skwi
skwi / gist:2405912
Created April 17, 2012 13:14
Unzip File
function unzip_file($file, $destination){
// create object
$zip = new ZipArchive() ;
// open archive
if ($zip->open($file) !== TRUE) {
die (’Could not open archive’);
}
// extract contents to destination directory
$zip->extractTo($destination);
// close archive
@skwi
skwi / gist:2414507
Created April 18, 2012 15:57
Récupérer une IP avec ou sans proxy
$ip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
@skwi
skwi / st_cheat.txt
Created April 23, 2012 08:30 — forked from bjhess/st_cheat.txt
Sublime Text Cheatsheet
Navigation:
cmd-p Goto Anything ('@' for functions, ':' for line number)
cmd-r Function finder
ctl-g Goto line number
cmd-sft-p Command palette
cmd-sft-f Find in Files
cmd-opt-r Toggle regex when finding
cmd-opt-# Columns
ctr-# Switch columns
@skwi
skwi / rmv-special-chars
Created November 23, 2012 09:10
remove html special chars
$__string__ = preg_replace("/&#?[a-z0-9]{2,8};/i","",$__string__);
@skwi
skwi / generatePassword.php
Last active December 15, 2015 13:48
Password generator
/**
* Generates a random Password
*
* @param integer $length The password length (8 characters default)
* @return string The password
*/
private function randomPassword($length = 8)
{
$alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
var confirmOnLeave = function(msg) {
window.onbeforeunload = function (e) {
e = e || window.event;
msg = msg || '';
// For IE and Firefox
if (e) {e.returnValue = msg;}
// For Chrome and Safari
{
"bold_folder_labels": true,
"caret_style": "wide",
"color_scheme": "Packages/Dayle Rees Color Schemes/Goldfish.tmTheme",
"detect_slow_plugins": false,
"drag_text": false,
"fade_fold_buttons": false,
"file_exclude_patterns":
[
"app/cache",