Skip to content

Instantly share code, notes, and snippets.

Avatar

Ferri Sutanto ghprod

  • Purwokerto, Indonesia
View GitHub Profile
View Readme.md

Requirments

  • bootstrap with typeahead
  • jquery

Explanation

This will use bootstrap with typeahead to create an autocomplete search.

@ghprod
ghprod / jQuery Simple Preload Images.js
Last active Dec 14, 2015
jQuery Simple Preload Images
View jQuery Simple Preload Images.js
function preload(arrayOfImages) {
$(arrayOfImages).each(function(){
$('<img />').attr('src',this).appendTo('body').hide();
});
}
// Usage:
preload([
'img/imageName.jpg',
View nginx + node setup.md

The idea is to have nginx installed and node installed. I will extend this gist to include how to install those as well, but at the moment, the following assumes you have nginx 0.7.62 and node 0.2.3 installed on a Linux distro (I used Ubuntu).

In a nutshell,

  1. nginx is used to serve static files (css, js, images, etc.)
  2. node serves all the "dynamic" stuff.

So for example, www.foo.com request comes and your css, js, and images get served thru nginx while everything else (the request for say index.html or "/") gets served through node.

  1. nginx listens on port 80.
View laravel-upload-resize.php
<?php
// Resizer and Image Manipulation
// Based on: http://forums.laravel.com/viewtopic.php?id=2648
public function post_edit_logo($id)
{
$rules = array(
'image' => 'image',
);
View fulltextsearch.php
public static function read_search($terms, $limit = 20)
{
$contact_results = Contact::where_account_user_id(Auth::user()->account_user_id)
->where_deleted(0)
->where_marketing(0)
->where_mass_merge(0)
->raw_where("match (`first`, `last`) against (?)", array($terms))
->take($limit)
->get();
View viewport.js
// -----------
// Debugger that shows view port size. Helps when making responsive designs.
// -----------
function showViewPortSize(display) {
if(display) {
var height = jQuery(window).height();
var width = jQuery(window).width();
jQuery('body').prepend('<div id="viewportsize" style="z-index:9999;position:fixed;top:40px;left:5px;color:#fff;background:#000;padding:10px">Height: '+height+'<br>Width: '+width+'</div>');
jQuery(window).resize(function() {
View eloquent.php
<?php
class Post
{
protected $table = 'posts';
/**
* You can define your own custom boot method.
*
* @return void
**/
View custom.js
$(document).ready(function() {
// Support for AJAX loaded modal window.
// Focuses on first input textbox after it loads the window.
$('[data-toggle="modal"]').click(function(e) {
e.preventDefault();
var url = $(this).attr('href');
if (url.indexOf('#') == 0) {
$(url).modal('open');
} else {
@ghprod
ghprod / BaseModel.php
Created Oct 10, 2013
BaseModel to extend Laravel Model and add some validation http://forums.laravel.io/viewtopic.php?pid=45695#p45695
View BaseModel.php
<?php
// models/BaseModel.php
class BaseModel extends Eloquent
{
/**
* Errors returned by the validator.
*
View get domain without subdomain.php
<?php
/**
* @param string $domain Pass $_SERVER['SERVER_NAME'] here
* @param bool $debug
*
* @debug bool $debug
* @return string
*/
function get_domain($domain, $debug = false)
{