Skip to content

Instantly share code, notes, and snippets.

View declum's full-sized avatar

Declum declum

View GitHub Profile
@declum
declum / Download_X_Lorem_Pixel_Images.sh
Created January 30, 2016 13:32 — forked from st-f/Download_X_Lorem_Pixel_Images.sh
Download X random images from lorempixel.com
# usage : sh download.sh 100
# will download 100 pics
START=1
for i in $(eval echo "{$START..$1}")
do
curl "http://lorempixel.com/index.php?generator=1&x=640&y=480&cat=" -o temp.html && cat temp.html | sed -n 's/.*<img src="\([^" ]*\)".*/\1/p' | awk '{print "http://lorempixel.com/"$1}' | xargs curl -o $i.jpg
done
@declum
declum / countries.php
Created January 24, 2016 11:57 — forked from ericlbarnes/countries.php
PHP Array of country names
<?php
return [
"Afghanistan",
"Albania",
"Algeria",
"Andorra",
"Angola",
"Antigua and Barbuda",
"Argentina",
#!/usr/bin/env python
"""Simple HTTP Server With Upload.
This module builds on BaseHTTPServer by implementing the standard GET
and HEAD requests in a fairly straightforward manner.
"""
#!/usr/bin/env python3
"""Simple HTTP Server With Upload.
This module builds on BaseHTTPServer by implementing the standard GET
and HEAD requests in a fairly straightforward manner.
see: https://gist.github.com/UniIsland/3346170
"""

When a user's session expires and they're on a page that uses ajax requests, you need to set up something to gracefully handle reauthenticating. In this example, we prompt the user and redirect them to the login page.

demo

For Laravel, in your auth filter:

<?php
Route::filter('auth', function()
{
{
"USD": {
"symbol": "$",
"name": "US Dollar",
"symbol_native": "$",
"decimal_digits": 2,
"rounding": 0,
"code": "USD",
"name_plural": "US dollars"
},
@declum
declum / TLDExtract.php
Created April 30, 2015 07:24
Extract Subdomain and TLDs from Domain Name
<?php
/**
* TLDExtract accurately extracts subdomain, domain and TLD components from URLs.
*
* Usage:
*
* $extract = new TLDExtract();
* $components = $extract('http://forums.news.cnn.com/'); //PHP 5.3 style. In PHP 5.2, use $extract->extract().
*

For the scenario, imagine posts has a foreign key user_id referencing users.id

public function up()
{
	Schema::create('posts', function(Blueprint $table) {
		$table->increments('id');
		$table->string('title');
		$table->text('body');
@declum
declum / isbn.php
Last active August 29, 2015 14:16
<?php
/**
* Query Amazon about a particular book by ISBN and obtain metadata.
* The author disclaims all copyright and places this in the public domain.
*
* Amazon's Terms of Use for this service require you to:
* - Send no more than 1 request every second
* - Direct traffic to them in some way. You can use the URL provided in the
* resulting metadata to achieve this.
*/
[
{
"model": "dmakr.domain",
"pk": 1,
"fields": {
"tld": "aero",
"country": "Air transport"
}
},{
"model": "dmakr.domain",