Skip to content

Instantly share code, notes, and snippets.

@ivanhoe011
ivanhoe011 / scrapper.js
Last active August 29, 2015 14:11
Tutsplus lesson scrapper (save in Chrome's Dev tools as a snippet)
// run from the index page of the course
(function () {
var urls = [],
videos = [];
// get lesson urls
$('.lesson-index__lesson-link').each( function () {
urls.push( $(this).attr('href') );
function scaleImage(ev)
{
var data = ev.data,
editor = ev.editor;
var img = data.image;
// maximum size allowed for images
var maxX = 400;
var maxY = 300;
@ivanhoe011
ivanhoe011 / laravel_auth_user_types.php
Last active August 29, 2015 14:15
How to authorize different types of users in L4/5
// in User.php model add few checks
public function is_admin()
{
return ($this->account_type === 'admin'); // account_type is ENUM field
}
public function has_rights($acc_type)
{
if ($this->is_admin()) { // if admin always true
return true;
@ivanhoe011
ivanhoe011 / wp_adv_search.php
Last active August 29, 2015 14:17
Advanced search example
<?php
// filter je upit koji zavisi od toga sta je popunjeno u pretrazi
$filter = array('relation' => 'AND');
// zavisno sta je od polja poslato u upitu kreiramo upit:
if ( ! empty($_GET['tip'])) { // ako pretrazujes po tipu nekretnine
$filter[] = array(
'key' => 'tip', // ovo je ime custom polja, recimo da je 'tip'
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit, working directory clean" ]] && echo "*"
}
parse_git_branch() {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/"
}
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;31m\] $(parse_git_branch)\[\033[00m\]\$ '
@ivanhoe011
ivanhoe011 / tmux-cheatsheet.markdown
Last active September 4, 2015 22:57 — forked from MohamedAlaa/tmux-cheatsheet.markdown
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@ivanhoe011
ivanhoe011 / sm-annotated.html
Last active September 14, 2015 11:20 — forked from hdragomir/sm-annotated.html
The deferred font loading logic for Smashing Magazine. http://www.smashingmagazine.com/
<script type="text/javascript">
(function () {
"use strict";
// once cached, the css file is stored on the client forever unless
// the URL below is changed. Any change will invalidate the cache
var css_href = './index_files/web-fonts.css';
// a simple event handler wrapper
function on(el, ev, callback) {
if (el.addEventListener) {
el.addEventListener(ev, callback, false);
/*
* An Angular service which helps with creating recursive directives.
* @author Mark Lagendijk
* @license MIT
*/
angular.module('foo').factory('RecursionHelper', ['$compile', function($compile){
return {
/**
* Manually compiles the element, fixing the recursion loop.
* @param element
@ivanhoe011
ivanhoe011 / functions.php
Created January 10, 2016 15:18
WP: Add category classes to <body>
// ...
add_filter('body_class','iii_inject_category_classs');
// add post's categories as css classes to <body> (with cat- prefix added)
function iii_inject_category_classs($classes) {
global $post;
if ($post and is_single($post)) {
foreach((get_the_category($post->ID)) as $cat) {
@ivanhoe011
ivanhoe011 / SVGClass.js
Last active February 20, 2016 14:19
Add/ Remove classes on SVG
/**
* Usage (where #map is ID of some element in svg document):
* $('#map').addSVGClass('some-class');
* $('#map').removeSVGClass('some-other-class');
*/
(function ($) {
$.fn.addSVGClass = function(className) {
var re = new RegExp('\\b'+ className +'\\b');
return this.each( function() {