Skip to content

Instantly share code, notes, and snippets.

View carusog's full-sized avatar
📚
Learning something new

Giuseppe Caruso carusog

📚
Learning something new
View GitHub Profile
Time::DATE_FORMATS[:my_custom_time] = "%B %d, %Y"
@carusog
carusog / python_joke.py
Created August 26, 2012 16:33
Python joke
while True:
for i in ["/","-","|","\\","|"]:
print "%s\r" % i,
@carusog
carusog / gist:3736733
Created September 17, 2012 11:11
Switch between buffers using alt+left/right arrow in Vim
" Switch between buffers using alt+left/right arrow
nnoremap <silent><A-Right> :bn<CR>
inoremap <silent><A-Right> <C-O>:bn<CR>
nnoremap <silent><A-Left> :bp<CR>
inoremap <silent><A-Left> <C-O>:bp<CR>
@carusog
carusog / shinywhitebox.js
Created December 29, 2012 15:26
How to delete default values in input fields on focus while keeping values typed by the user with jQuery
// Detetes default value in input fields but not user inserted text
default_values = {};
$email = $('input#email');
$email.each(function () {
var index = $(this).attr('name');
var value = $(this).val();
default_values[index] = value;
});
$.fn.toggleClick = function(){
var methods = arguments, // store the passed arguments for future reference
count = methods.length; // cache the number of methods
//use return this to maintain jQuery chainability
return this.each(function(i, item){
// for each element you bind to
var index = 0; // create a local counter for that element
$(item).click(function(){ // bind a click handler to that element
return methods[index++ % count].apply(this,arguments); // that when called will apply the 'index'th method to that element
@carusog
carusog / CSS Animated Hamburger Icon for Bootstrap.markdown
Last active September 11, 2017 19:58
CSS Animated Hamburger Icon for Bootstrap

CSS Animated Hamburger Icon for Bootstrap

Bootstrap Animated Hamburger Icon with CSS transforms. No changes to any HTML required, just add the classes. The built-in "collapsed" class on the button will take care of transformations.

Some pens around use JavaScript to toggle .collapsed class on clicked .navbar-toggle (AKA the hamburger) since they suppose there is a bug in Bootstrap.js that doesn't toggle that class. It seems, instead (I didn't inspect the code), that .collapsed class is added only while using a class or an anchor name as collapsable target element. (credits: http://stackoverflow.com/a/31076793/877464)

A Pen by Giuseppe Caruso on CodePen.

@carusog
carusog / controllers.application.js
Last active December 13, 2016 21:29
Validating form fields
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
@carusog
carusog / debug-snippets.less
Last active April 8, 2019 07:54
Some snippets I use for debugging CSS
// LESS
.debug(@color: red, @opacity: 20%) {
background-color: fade(@color, @opacity);
}
@carusog
carusog / component-element-instance.ts
Last active April 8, 2019 07:58
how to access your component element instance
import {
ElementRef
} from '@angular/core';
// omitted code
constructor(private el: ElementRef) {
console.log('###element', el);
}
@carusog
carusog / query-param.service.ts
Created July 25, 2019 15:00
An Angular service to parse and get specific query parameters from URI
import {URLSearchParams} from '@angular/http';
export class QueryParamService {
get(name: string) {
const params = new URLSearchParams(window.location.search.substring(1));
const param = params.get(name);
return param === null ? null : decodeURIComponent(param);
}