Skip to content

Instantly share code, notes, and snippets.

@cereal-s
cereal-s / curl_get_headers.php
Created January 20, 2014 11:09
Simple snippet, used to check the redirects of the links. Requires cURL.
<?php
$url = false;
if($_POST)
{
$url = $_POST['url'];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
@cereal-s
cereal-s / php_get_header.php
Created January 20, 2014 11:13
Simple snippet, used to get the headers from link and his redirects. Requires PHP 5.1.3 and above.
<?php
$url = false;
if($_POST)
{
$url = $_POST['url'];
stream_context_set_default(array('http' => array('method' => 'HEAD')));
$headers = get_headers($url, 0);
@cereal-s
cereal-s / dtime.php
Last active January 4, 2016 12:19
Format localized dates. Requires at least PHP 5.3.0 and the Intl library, the latter can be installed from cli: sudo apt-get install php5-intl
<?php
class Dtime extends IntlDateFormatter
{
private $date;
public function __construct($datetime = '', $pattern = 'd MMMM yyyy HH:mm', $locale = 'it')
{
parent::__construct($locale, IntlDateFormatter::FULL, IntlDateFormatter::FULL);
<?php
# AJAX filter for Laravel 4.2
# this goes in app/start/global.php
Route::filter('ajax', function($route, $request) {
if ($request->ajax() === FALSE)
return App::abort(500);
});
@cereal-s
cereal-s / appify
Last active August 29, 2015 14:21 — forked from mathiasbynens/appify
#!/bin/bash
if [ "$1" = "-h" -o "$1" = "--help" -o -z "$1" ]; then cat <<EOF
appify v3.0.1 for Mac OS X - http://mths.be/appify
Creates the simplest possible Mac app from a shell script.
Appify takes a shell script as its first argument:
`basename "$0"` my-script.sh
@cereal-s
cereal-s / 1_README.md
Created May 14, 2016 13:40 — forked from Daniel15/1_README.md
Complete Google Drive File Picker example

Google Drive File Picker Example

This is an example of how to use the Google Drive file picker and Google Drive API to retrieve files from Google Drive using pure JavaScript. At the time of writing (14th July 2013), Google have good examples for using these two APIs separately, but no documentation on using them together.

Note that this is just sample code, designed to be concise to demonstrate the API. In a production environment, you should include more error handling.

See a demo at http://stuff.dan.cx/js/filepicker/google/

@cereal-s
cereal-s / helper.route.php
Last active August 23, 2016 14:04
_route() function for SlimPHP 3.4.2, it returns the path for the named route
<?php
if( ! function_exists('_route'))
{
/**
* Return the path for the named route
*
* @see http://www.slimframework.com/docs/objects/router.html#route-names
* @param string $name
* @param array $parameters
@cereal-s
cereal-s / crawler-edit.php
Created September 6, 2016 14:54 — forked from jakzal/crawler-edit.php
Removing nodes with DomCrawler
<?php
<<<CONFIG
packages:
- "symfony/dom-crawler: ~2.3"
- "symfony/css-selector: ~2.3"
CONFIG;
use Symfony\Component\DomCrawler\Crawler;
$html = <<<HTML
@cereal-s
cereal-s / sqlite.strstr.sql
Created September 25, 2016 13:31
SQLite strstr()
-- return the domain name
SELECT SUBSTR('[email protected]'
, INSTR('[email protected]', '@') + 1
, LENGTH('[email protected]') - INSTR('[email protected]', '@'));
@cereal-s
cereal-s / sublime-settings-osx.json
Created November 21, 2016 11:45 — forked from arvi/sublime-settings-osx.json
Sublime Settings OSX
{
"auto_complete_triggers":
[
{
"characters": "<",
"selector": "text.html"
},
{
"characters": ".",
"selector": "source.js"