Skip to content

Instantly share code, notes, and snippets.

@izumskee
izumskee / replaceJquery
Created September 11, 2014 16:16
hasClass/addClass/removeClass/toggleClass in pure javascript
Element.prototype.hasClass = function (className) {
return new RegExp(' ' + className + ' ').test(' ' + this.className + ' ');
};
Element.prototype.addClass = function (className) {
if (!this.hasClass(className)) {
this.className += ' ' + className;
}
return this;
};
@izumskee
izumskee / 0_reuse_code.js
Last active August 29, 2015 14:11
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@izumskee
izumskee / media-queries
Created January 4, 2015 20:37
media-queries
/* Smartphones (portrait and landscape) ----------- */
@media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) {
/* STYLES GO HERE */
}
/* Smartphones (landscape) ----------- */
@media only screen
and (min-width : 321px) {
@izumskee
izumskee / gitignore
Created January 10, 2015 09:26
Git ignore file
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
# Packages #
@izumskee
izumskee / XMLHttpRequest_example.js
Created March 17, 2015 11:54
XMLHttpRequest example
var httpRequest;
if (window.XMLHttpRequest) {
httpRequest = new XMLHttpRequest();
} else if (window.ActiveXObject) {
// Internet Explorer
httpRequest = new
ActiveXObject("Microsoft.XMLHTTP");
}
httpRequest.onreadystatechange = function () {
if (httpRequest.readyState === 4 && httpRequest.status === 200) {
@izumskee
izumskee / calculate_scroll_speed
Created April 15, 2015 20:05
Calculate Scroll Speed
// Calculate Scroll Speed
var lastOffset = $(window).scrollTop();
var lastDate = new Date().getTime();
$(window).scroll(function(e) {
var delayInMs = e.timeStamp - lastDate;
var offset = scrollTopValue - lastOffset;
var speedInpxPerMs = offset / delayInMs;
var scrollSpeed = Math.abs(speedInpxPerMs.toFixed(2));
@izumskee
izumskee / gist:017601a44b89d9ca4737
Created May 13, 2015 15:11
offset google maps center
function offsetCenter(map, latlng, offsetx, offsety) {
// latlng is the apparent centre-point
// offsetx is the distance you want that point to move to the right, in pixels
// offsety is the distance you want that point to move upwards, in pixels
// offset can be negative
// offsetx and offsety are both optional
var scale = Math.pow(2, map.getZoom());
var nw = new google.maps.LatLng(
@izumskee
izumskee / meteorWrapAsync.js
Created August 1, 2015 10:27
Use Async Functions With Meteor
var GithubAPI = Meteor.require('github');
var ghapi = new GithubAPI({version: "3.0.0"});
function getUserProfile(req, callback) {
ghapi.user.getFrom(req, callback);
}
var wrappedGetProfile = Meteor._wrapAsync(getUserProfile);
Meteor.methods({
@izumskee
izumskee / throwErrorMeteor.js
Last active August 29, 2015 14:26
Smooth error handling for Meteor.methods
// in /lib needed on both client and server
var throwError = function(error, reason, details) {
error = new Meteor.Error(error, reason, details);
if (Meteor.isClient) {
return error;
} else if (Meteor.isServer) {
throw error;
}
};
cd ~/bundle/programs/server/npm
rm -rf npm-bcrypt/node_modules/bcrypt
npm install bcrypt@0.7.7