Skip to content

Instantly share code, notes, and snippets.

@silicakes
silicakes / nodeJSCustomPadding.js
Last active October 2, 2022 06:34
NodeJS Crypto custom padding example
// Following an answer I posted to my question here:
// http://stackoverflow.com/questions/21856892/node-crypto-aes256-cbc-0x0-padding-example/21858749#21858749
//I'm expecting a utf8 encoded string
function customPadding(str, blockSize, padder, format) {
str = new Buffer(str,"utf8").toString(format);
//1 char = 8bytes
var bitLength = str.length*8;
// a string interpolator, extending the String object,
// returns a new string with the values in the curly braces replaced
// with the ones provided by a passed object.
String.prototype.interpolate = function(obj) {
var buf = this;
for(x in obj) {
var re = new RegExp("{"+x+"}","g");
buf = buf.replace("{"+x+"}", obj[x]);
}
@silicakes
silicakes / invertRegex.js
Last active August 29, 2015 14:09
Invert javascript regex
// sometimes it easier to select something constant rather than amorphic
// the following function allows the inversion of such regular expression
// while returning an array of the inverted matched results
//<regex> | object - the desired regular expression
//<str> | string - the string on which the manipulation will occur
//<clear> | boolean - whether should the return array be emptied out of empty cells: ["",1,2,""] -> [1,2]
function invertRegex(str, regex, clear) {
var arr = str.split(regex);
@silicakes
silicakes / getURLsFromCSS.js
Created March 28, 2016 09:53
get all interna, external and data URLs present inside a stylesheet
/**
* @description Returns all image/font/whatever URLs from all stylesheets present in the document
* @param styles {object|StyleSheetList} https://developer.mozilla.org/en-US/docs/Web/API/StyleSheetList
* @returns {array|string}
*/
function getURLsFromCSS(styles) {
var urls = [];
for (var x in styles) {
var style = styles[x];
@silicakes
silicakes / index.html
Created June 20, 2017 08:29
Pure CSS switch
<div class="switch-wrapper">
<input type="checkbox" class="checkbox" id="checkbox"/>
<label for="checkbox" class="switch" data-off="off" data-on="on"/>
</div>
@silicakes
silicakes / everyPred.js
Last active July 30, 2017 15:20
Takes a set of predicates and returns a function f that returns true if all of its composing predicates return a logical true value against all of its arguments.
/*
* @description
* ported from Clojure's own [(every-pred)](https://clojuredocs.org/clojure.core/every-pred)
* array.everyPred(pred0, pred1...predN)
*
* From Clojure's documentation:
* Takes a set of predicates and returns a function f that returns true if all of its composing predicates return a logical true
* value against all of its arguments, else it returns false.
* Note that f is short-circuiting in that it will stop execution on the first argument that triggers a -
* logical false result against the original predicates.
@silicakes
silicakes / CodeComponent.template.tsx
Last active December 31, 2018 15:20
Framers code component template
import * as React from "react";
import { PropertyControls, ControlType } from "framer";
const style: React.CSSProperties = {
height: "100%",
display: "flex",
alignItems: "center",
justifyContent: "center",
textAlign: "center",
color: "#8855FF",
import * as React from "react";
import { render } from "react-dom";
import "./styles.css";
function App(props) {
return (
<div className="App">
<h1> {props.text}</h1>
</div>
import * as React from "react";
import { render } from "react-dom";
import "./styles.css";
function App(props) {
return (
<div className="App">
<h1> {props.text}</h1>
</div>