Skip to content

Instantly share code, notes, and snippets.

View msurguy's full-sized avatar

Maksim Surguy msurguy

View GitHub Profile
@msurguy
msurguy / model.php
Created March 11, 2013 19:10
Get created_at date in different formats with Laravel in PHP 5.2+. Put this code in your model (for example models/users.php) and in your views do {{ $user->short_created_at }}
public function get_short_created_at()
{
$date = $this->get_attribute('created_at');
if (is_string($date)){
$dateObject = DateTime::createFromFormat('Y-m-d H:i:s', $date);
return $dateObject->format('Y-m-d');
}
return $date;
}
@msurguy
msurguy / DB.sql
Last active March 21, 2025 14:46
Dynamic dropdown in Laravel, let's say you have multiple drop downs (selects), you click on one and the contents of the other need to be dynamically changed. One solution is to dynamically load JSON from the API and change the dropdown dynamically depending on the user choice.
CREATE TABLE `makers` (
`id` int(10) unsigned NOT NULL,
`name` varchar(255) NOT NULL,
`description` varchar(255) NOT NULL,
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
This file has been truncated, but you can view the full file.
'use strict';
var COMPILED = !0, goog = goog || {};
goog.global = this;
goog.DEBUG = !1;
goog.LOCALE = "en";
goog.provide = function (a) {
if (!COMPILED) {
if (goog.isProvided_(a))
throw Error('Namespace "' + a + '" already declared.');
delete goog.implicitNamespaces_[a];
@msurguy
msurguy / routes.php
Created March 14, 2013 01:16
Laravel redirect to last visited page if not logged in
Route::filter('auth', function()
{
if (Auth::guest())
{
// Save the attempted URL
Session::put('pre_login_url', URL::current());
// Redirect to login
return Redirect::to('login');
}
@msurguy
msurguy / index.html
Created March 21, 2013 23:45
A CodePen by Maksim Surguy. Wallpaper generator - Dynamically generated wallpaper
<button id="generateBtn">Show Wallpaper</button>
<select id="res">
<option value="1">800x600</option>
<option value="2">1200x800</option>
<option value="3">1600x1200</option>
<option value="4">1920x1600</option>
</select>
<br>
@msurguy
msurguy / resetpass.php
Created March 27, 2013 01:24
Reset user's password in Laravel 3 through artisan command . Put this file into application/tasks Usage from command line : php artisan resetpass 1 nEwP@SSwOrd Where 1 is user's id and "nEwP@SSwOrd" is the new password
<?php
class Resetpass_Task {
public function run($arguments)
{
$userid = $arguments[0];
$newpass = $arguments[1];
$user = User::find($arguments[0]);
if($user){
@msurguy
msurguy / gist:5287095
Created April 1, 2013 19:29
Using Excel Bundle in Laravel
Route::get('excel', function(){
$objPHPExcel = new PHPExcel();
$sheet = $objPHPExcel->getActiveSheet();
$sheet->setCellValue('A1','Test value');
$writer = new PHPExcel_Writer_Excel5($objPHPExcel);
$writer->save("test.xls");
return Response::download('test.xls', 'test.xls');
});
@msurguy
msurguy / gist:5287103
Created April 1, 2013 19:30
Using FTP bundle in Laravel
Route::get('ftp', function(){
$ftp = SFTP::make('example.com', 'username', 'password');
// connect to FTP server
if($ftp->connect()) {
print "Connection successful";
// download a file from FTP server
// will download file "somefile.php" and
// save locally as "localfile.php"
@msurguy
msurguy / gist:5287280
Created April 1, 2013 19:57
PhoneGap resources
https://github.com/ccoenraets/phonegap-workshop-solutions
http://blog.stevensanderson.com/2011/10/05/full-height-app-layouts-a-css-trick-to-make-it-easier/
@msurguy
msurguy / instructions.js
Created April 11, 2013 06:25
Blueimp image upload + cropping on the server as described in https://github.com/blueimp/jQuery-File-Upload/issues/1314
Hi. To integrate jcrop i used a done callback. This means i add jcrop only after successful upload. In general its look like this: on done you have data object. Data.result is an array of files' information returned from server. For each file (image) you need to create separate cropbox, and initialize jcrop plugin for each cropbox after image was loaded. Than post that data to server and handle croping of image on server side. Well, it's my solution, but there are many another ways.
Code:
var cropbox_indx = 0, //index of cropbox
img_data = {}, // keeps uploaded image data
crop_w = 150,
crop_h = 125;