Skip to content

Instantly share code, notes, and snippets.

View rediris's full-sized avatar
💭
😸

Roman Edirisinghe rediris

💭
😸
  • United States
View GitHub Profile
@Xodarap
Xodarap / toggleAttr.js
Created May 21, 2011 14:40
jQuery toggle attribute
(function ($) {
$.fn.toggleAttr = function (attr, val1, val2) {
///<summary>Toggles an attribute between having one of two possible states</summary>
///<param name="attr">Attribute name</param>
///<param name="val1">First value</param>
///<param name="val2">Second value</param>
return this.each(function () {
var $this = $(this);
if ($this.attr(attr) === val1) {
@olivierlacan
olivierlacan / launch_sublime_from_terminal.markdown
Created September 5, 2011 15:50
Launch Sublime Text 2 from the Mac OS X Terminal

Launch Sublime Text 2 from the Mac OS X Terminal

Sublime Text 2 ships with a CLI called subl (why not "sublime", go figure). This utility is hidden in the following folder (assuming you installed Sublime in /Applications like normal folk. If this following line opens Sublime Text for you, then bingo, you're ready.

open /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl

You can find more (official) details about subl here: http://www.sublimetext.com/docs/2/osx_command_line.html

Installation

@addyosmani
addyosmani / objExtend.js
Created September 16, 2011 12:08
JavaScript object 'namespace' extension experiments
$(function(){
//===========================================================
// JavaScript object 'namespace' extension experiments
// by @addyosmani (comparing deep extension in vanilla JS vs.
// jQuery's $.extend)
//
//
// The goal here is to:
//
@iwek
iwek / find-in-json.js
Created October 20, 2012 21:43
Searching through JSON
//return an array of objects according to key, value, or key and value matching
function getObjects(obj, key, val) {
var objects = [];
for (var i in obj) {
if (!obj.hasOwnProperty(i)) continue;
if (typeof obj[i] == 'object') {
objects = objects.concat(getObjects(obj[i], key, val));
} else
//if key matches and value matches or if key matches and value is not passed (eliminating the case where key matches but passed value does not)
if (i == key && obj[i] == val || i == key && val == '') { //
@jareware
jareware / SCSS.md
Last active April 23, 2024 22:13
Advanced SCSS, or, 16 cool things you may not have known your stylesheets could do

⇐ back to the gist-blog at jrw.fi

Advanced SCSS

Or, 16 cool things you may not have known your stylesheets could do. I'd rather have kept it to a nice round number like 10, but they just kept coming. Sorry.

I've been using SCSS/SASS for most of my styling work since 2009, and I'm a huge fan of Compass (by the great @chriseppstein). It really helped many of us through the darkest cross-browser crap. Even though browsers are increasingly playing nice with CSS, another problem has become very topical: managing the complexity in stylesheets as our in-browser apps get larger and larger. SCSS is an indispensable tool for dealing with this.

This isn't an introduction to the language by a long shot; many things probably won't make sense unless you have some SCSS under your belt already. That said, if you're not yet comfy with the basics, check out the aweso

@wycks
wycks / image_optimize-wordpress.php
Last active December 16, 2020 01:48
Remove WordPress full size images from being inserted into a post + option to and add max size to to prevent users from inserting massive images.
<?php
/**
*
* This removes the ability to add the FULL image size into a post, it does not alter or delete the image
* Add whataever extra image sizes to the insert dropdown in WordPress you create via add_image_size
*
* For now we have to do it this way to make the labels translatable, see trac ref below.
*
* If your theme has $content_width GLOBAL make sure and remove it
@tommcfarlin
tommcfarlin / jquery-boilerplate.js
Created March 7, 2013 16:12
[WordPress] Properly loading jQuery within WordPress without having to use the `noConflict` method, or creating your own reference such as `$wp = jQuery`.
/**
* This gist demonstrates how to properly load jQuery within the context of WordPress-targeted JavaScript so that you don't
* have to worry about using things such as `noConflict` or creating your own reference to the jQuery function.
*
* @version 1.0
*/
(function( $ ) {
"use strict";
$(function() {
@zoerooney
zoerooney / no-li-nav-menu-v1.php
Last active February 3, 2020 08:49
Create an arguably cleaner nav menu in WordPress. Version 1 replacing the LI elements in a WordPress menu with SPAN elements, while maintaining classes, etc., while version 2 results in just A elements, still maintaining all the classes, etc. Post: http://zoerooney.com/blog/tutorials/removing-list-items-wordpress-menus/
<?php
// first let's get our nav menu using the regular wp_nav_menu() function with special parameters
$cleanmenu = wp_nav_menu( array(
'theme_location' => 'social', // we've registered a theme location in functions.php
'container' => false, // this is usually a div outside the menu ul, we don't need it
'items_wrap' => '<nav id="%1$s" class="%2$s">%3$s</nav>', // replacing the ul with nav
'echo' => false, // don't display it just yet
) );
@mrosati84
mrosati84 / toggleClass.html
Created October 2, 2013 10:52
Simple toggleClass implemented in AngularJS
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
.is-active {
color: red;
}
</style>
@iwek
iwek / imagedata-to-filename.js
Created October 23, 2013 20:37
Convert CANVAS data to binary data and then to a filename using a Blob
function binaryblob(){
var byteString = atob(document.querySelector("canvas").toDataURL().replace(/^data:image\/(png|jpg);base64,/, ""));
var ia = new Uint8Array(ab);
for (var i = 0; i < byteString.length; i++) {
ia[i] = byteString.charCodeAt(i);
}
var dataView = new DataView(ab);
var blob = new Blob([dataView], {type: "image/png"});
var DOMURL = self.URL || self.webkitURL || self;
var newurl = DOMURL.createObjectURL(blob);