Skip to content

Instantly share code, notes, and snippets.

@jimode
jimode / context-and-localstorage-using-hooks.js
Last active June 10, 2024 11:16
Providing Context and Local Storage Using Hooks
// Providing Context
// ==================
import React, {useState, useEffect} from "react"
const Context = React.createContext()
function ContextProvider({children}) {
const [allPhotos, setAllPhotos] = useState([])
const [cartItems, setCartItems] = useState([])
@kendricktan
kendricktan / capsule_networks.py
Last active August 17, 2021 17:12
Clean Code for Capsule Networks
"""
Dynamic Routing Between Capsules
https://arxiv.org/abs/1710.09829
"""
import torch
import torch.nn as nn
import torch.optim as optim
import torch.nn.functional as F
import torchvision.transforms as transforms
@tralves
tralves / get_indexdb_sizes.js
Last active March 9, 2024 13:34
Calculate sizes of all IndexDB database and tables
var getTableSize = function(db, dbName){
return new Promise((resolve,reject) => {
if (db == null) {
return reject();
}
var size = 0;
db = event.target.result;
var transaction = db.transaction([dbName])
.objectStore(dbName)
.openCursor();
@juhap
juhap / service_clp_serializer.ftl
Created July 31, 2012 08:40
Liferay CLP serializer that handles also classes not generated by service builder
package ${packagePath}.service;
<#assign entitiesHaveColumns = false>
<#list entities as entity>
<#if entity.hasColumns()>
<#assign entitiesHaveColumns = true>
import ${packagePath}.model.${entity.name}Clp;
</#if>
@mathewbyrne
mathewbyrne / slugify.js
Created October 12, 2011 04:34
Javascript Slugify
function slugify(text)
{
return text.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
.replace(/-+$/, ''); // Trim - from end of text
}