Skip to content

Instantly share code, notes, and snippets.

View muhamed-didovic's full-sized avatar
😎

Muhamed muhamed-didovic

😎
View GitHub Profile
<?php
# Instead of
$name = 'Jeff';
switch ($name) {
case 'Jeff':
echo "I'm Jeff";
break;
case 'Joe':
@muhamed-didovic
muhamed-didovic / main.js
Last active August 29, 2015 14:11 — forked from jacekd/main.js
$(window).scroll(function() {
var scroll = $(window).scrollTop();
if (scroll > 50) {
$(".menu-bar").addClass("menu-bar-scroll");
} else {
$(".menu-bar").removeClass("menu-bar-scroll");
}
});
(function(){
/*
<a href="posts/2" data-method="delete"> <---- We want to send an HTTP DELETE request
- Or, request confirmation in the process -
<a href="posts/2" data-method="delete" data-confirm="Are you sure?">
*/
(function() {
$(document).ready(function() {
// Add click handler to hyperlinks to send restful DELETE requests
//
// Example:
//
// <a href="/delete/1" class="rest-delete">delete</a>
// <script>restful.init($('.rest-delete'));</script>
//
var restful = {
<?php
class PhotoApiTest extends TestCase {
public function setUp()
{
parent::setUp();
Route::enableFilters();
(function($, undefined) {
// Shorthand to make it a little easier to call public laravel functions from within laravel.js
var laravel;
$.laravel = laravel = {
// Link elements bound by jquery-ujs
linkClickSelector: 'a[data-confirm], a[data-method], a[data-remote], a[data-disable-with]',
// Select elements bound by jquery-ujs
inputChangeSelector: 'select[data-remote], input[data-remote], textarea[data-remote]',
var o = $({});
$.subscribe = o.on.bind(o);
$.publish = o.trigger.bind(o);
<?php
// more: http://baylorrae.com/php-pubsub/
class PubSub
{
private static $events = array(); // all subscriptions
// Don't allow PubSub to be initialized outside this class
@muhamed-didovic
muhamed-didovic / partial.js
Created December 19, 2014 13:29
partial application javascript
function partial( fn /*, args...*/) {
var aps = Array.prototype.slice,
args = aps.call( arguments, 1 );
return function() {
return fn.apply( this, args.concat( aps.call( arguments ) ) );
};
}
// VERY BORING EXAMPLE
@muhamed-didovic
muhamed-didovic / hint.txt
Last active August 29, 2015 14:11
some php hints
array_combine() — Creates an array by using one array for keys and another for its values (useful when reading from a CSV file - combine the header row with each subsequent line to create an associative array)
fgetcsv() — Gets line from file pointer and parse for CSV fields
register_shutdown_function() — Register a function for execution on shutdown
stream_context_create() — Creates a stream context (perform a POST using file_get_contents)
parse_url() — Parse a URL and return its components
uniqid() — Generate a unique ID
money_format() — Formats a number as a currency string
wordwrap() — Wraps a string to a given number of characters
Also, for anyone wondering, in the OP, mysql() is an alias of: