Skip to content

Instantly share code, notes, and snippets.

@ofca
ofca / styles.css
Last active November 24, 2015 10:07
Minor fixes for new ("material design") Google Plus
/**
* Changelog:
*
* 2015/11/24
* - display full content of the posts and remove "read more" dots
* - display all comments (no need to scroll)
*/
.fu5e3b.qhIQqf {
/* Show full post */
@ofca
ofca / 404 laravel logs
Created October 23, 2014 13:00
Maybe someone find this useful - regex pattern to match all 404 errors in the Laravels logs.
^\[[^\]]+\].*NotFoundHttpException.*[^\[]+\[\] \[\]
.row {
margin: 0 -5px
}
.col {
width: 25%;
padding: 0 5px;
}
<?php
$strings = array(
'/bundle/foo/login',
'/bundle/foo/notLogin',
'/bundle/foo/loginNot',
'/bundle/foo/bar'
);
foreach ($strings as $string) {
@ofca
ofca / fix_docstring.py
Created November 14, 2013 00:11
This script will fix docstrings in javascript files compiled by CoffeeScript.
from optparse import OptionParser
import pprint
import os
import sys
import re
parser = OptionParser(usage="This script will fix docstrings in javascript files compiled by CoffeeScript.")
parser.add_option('-s', '--src', help='source directory')
(options, args) = parser.parse_args()
// Input array
var input = [
{ id: 1, name: 'Tom', status: 'Accepted', category: 'Admin' },
{ id: 2, name: 'Chris', status: 'Not accepted', category: 'Moderator' },
{ id: 3, name: 'July', status: 'Accepted', category: 'Moderator' },
{ id: 4, name: 'John', status: 'To verify', category: 'Admin' },
{ id: 5, name: 'Jeff', status: 'Accepted', category: 'Admin' },
{ id: 6, name: 'Andrew', status: 'Accepted', category: 'Admin' },
];
/**
* $defaults = array(
* 'a' => 2
* 'b' => 2
* );
* $untrusted = array(
* 'a' => 4,
* 'c' => 4
* );
* print_r(arrayMergeDefault($default, $unstrusted));
@ofca
ofca / input.placeholder.js
Last active December 17, 2015 23:29
Nicer version of HTML5 "placeholder" attribute.
$('[data-placeholder]').each(function() {
var $this = $(this),
text = $this.attr('data-placeholder');
if ($this[0].nodeName == 'TEXTAREA') {
$this.text(text);
} else {
$this.val(text);
}
@ofca
ofca / $.3.js
Last active February 20, 2021 13:30
// based on https://gist.github.com/Potfur/5576225 & https://github.com/james2doyle/saltjs
// more info: https://plus.google.com/109231487156400680487/posts/63eZzzrBSb6
window.$ = function(s) {
var c = {
'#': 'ById',
'.': 'sByClassName',
'@': 'sByName',
'=': 'sByTagName'}[s[0]];
return document[c?'getElement'+c:'querySelectorAll'](s.slice(1))
};
@ofca
ofca / Browser.php
Created February 26, 2013 19:21
Browser helper class.
<?php
class Browser
{
public static function isMobile()
{
$useragent=$_SERVER['HTTP_USER_AGENT'];
return (preg_match('/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i',$useragent)||preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\