Skip to content

Instantly share code, notes, and snippets.

@jp26jp
jp26jp / .htaccess
Created April 17, 2016 18:35
Prevent browser from caching website's files.
<IfModule mod_headers.c>
Header set Cache-Control "no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires 0
</IfModule>
@jp26jp
jp26jp / .htaccess
Created June 16, 2016 02:02
Change home page to index.php
DirectoryIndex index.php
@jp26jp
jp26jp / script.js
Created June 16, 2016 19:53
Incrementally add a new ID to each selector
var i = 0;
$('.class').each(function() {
i++;
var newID = 'section'+i;
$(this).attr('id',newID);
});
var colors = {}
Cookie.set('main', '#333');
$('#main').spectrum({
color: Cookie.get('main'), // gets the value of the 'main' cookie and sets it as the initial color
change: function(color){
colors.main = color.toHexString(); // returns the selected color as a hex string and assigns it to a 'main' property of the colors object
Cookie.set('main', colors.main); // updates the value of the 'main' cookie
}
});
@jp26jp
jp26jp / .html
Created June 27, 2016 16:40
Fixes inputs for 3rd party services in Muse
<style>
input[type='text'] {
-webkit-appearance:textfield;
}
input[type='radio'] {
-webkit-appearance:radio;
}
input[type='checkbox'] {
-webkit-appearance:checkbox;
}
@jp26jp
jp26jp / script.js
Last active July 5, 2016 19:21
Remove all stored keys in Ecwid
var keyNames = [];
// function to delete each key from storage one by one
deleteAllStorageData = function (array){
for (i=0; i < array.length; i++) {
$.ajax({
url: 'https://app.ecwid.com/api/v3/' + storeId + '/storage/' + array[i] + '?token=' + accessToken,
type: 'DELETE'
})
}
console.log('DELETED');
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
@jp26jp
jp26jp / visibility.js
Created August 7, 2016 20:13
Find whether a tab is visible with Page Visibility API
var hidden, visibilityState, visibilityChange;
if (typeof document.hidden !== "undefined") {
hidden = "hidden", visibilityChange = "visibilitychange", visibilityState = "visibilityState";
}
else if (typeof document.mozHidden !== "undefined") {
hidden = "mozHidden", visibilityChange = "mozvisibilitychange", visibilityState = "mozVisibilityState";
}
else if (typeof document.msHidden !== "undefined") {
hidden = "msHidden", visibilityChange = "msvisibilitychange", visibilityState = "msVisibilityState";
}
@jp26jp
jp26jp / throws.swift
Created August 16, 2016 13:59
Check if dictionary and/or dictionary key exists
enum ParserError: ErrorType {
case EmptyDictionary
case InvalidKey
}
struct Parser {
var data: [String : String?]?
func parse() throws {
guard let _ = data else {
@jp26jp
jp26jp / script.js
Created September 11, 2016 09:36
Programmatically increase color hex brightness
function increase_brightness(hex, percent){
// strip the leading # if it's there
hex = hex.replace(/^\s*#|\s*$/g, '');
// convert 3 char codes --> 6, e.g. `E0F` --> `EE00FF`
if(hex.length == 3){
hex = hex.replace(/(.)/g, '$1$1');
}
var r = parseInt(hex.substr(0, 2), 16),