Skip to content

Instantly share code, notes, and snippets.

@Usse
Usse / db.php
Created May 20, 2013 12:46
Fast and dirty PHP db connect
<?php
$mysql_hostname = "hostname";
$mysql_user = "username";
$mysql_password = "password";
$mysql_database = "database";
$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password)
or die("Connection error");
mysql_select_db($mysql_database, $bd) or die("DB selection error");
?>
@Usse
Usse / gallery.js
Created May 7, 2013 12:34
General gallery
@Usse
Usse / test_if_link.js
Created April 29, 2013 16:37
Wrap with an <a> element all the link occurrences in a string.
@Usse
Usse / test_if_hashtag.js
Created April 29, 2013 16:36
Wrap with an <a> element all the '#tag' occurrences in a string. Usefull for twitter json.
function test_if_hashtag(string) {
var thestring=string;
var pattern = /#([a-zA-Z0-9]+)/g;
return thestring.replace(pattern, "<a href='https://twitter.com/search?q=%23$1' target='_blank'>#$1</a>");
}
@Usse
Usse / server.js
Created February 27, 2013 09:20
Node.js server file that redirect all the paths without extension to the index. Usefull for AngularJS development.
var serverPort = 3000;
var express = require("express"),
app = express(),
port = serverPort;
app.use(express.methodOverride());
app.use(express.bodyParser());
@Usse
Usse / clearfix.scss
Created February 3, 2013 16:03
Sass version of clearfix
.cf {
zoom: 1;
&:before,
&:after {
content: '';
display: table;
}
&:after {
clear: both;
}
@Usse
Usse / mediaQuery.css
Created January 24, 2013 13:02
Usefull Mediaquery to target the mobile world
/* Smartphones (portrait and landscape) */
@media only screen and (min-device-width : 320px) and (max-device-width : 480px) {}
/* Smartphones (landscape) */
@media only screen and (min-width : 321px) {}
/* Smartphones (portrait) */
@media only screen and (max-width : 320px) {}
/* iPads (portrait and landscape) */
@Usse
Usse / pngFix.js
Created January 18, 2013 10:42
Fix for PNG transparency issue in IE when fading images
var i;
for (i in document.images) {
if (document.images[i].src) {
var imgSrc = document.images[i].src;
if (imgSrc.substr(imgSrc.length-4) === '.png' || imgSrc.substr(imgSrc.length-4) === '.PNG') {
document.images[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',sizingMethod='crop',src='" + imgSrc + "')";
}
}
}
@Usse
Usse / cookies.js
Created December 6, 2012 09:32
Gets or sets cookies
/**
* Gets or sets cookies
* @param name
* @param value (null to delete or undefined to get)
* @param options (domain, expire (in days))
* @return value or true
*/
_.cookie = function(name, value, options)
{
if (typeof value === "undefined") {
@Usse
Usse / backward.js
Created December 3, 2012 13:19
jQuery backward each
jQuery.fn.reverse = [].reverse;
$(elements).reverse().each(function(index,item) {
//...some awesome code
});