Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View SaleRise's full-sized avatar

SaleRise Free Website Builder SaleRise

View GitHub Profile
@servercharlie
servercharlie / client.js
Last active February 1, 2018 05:18
Proper PIXI window resizing, w/ jQuery.
/*
- Insert this after:
- referencing jquery.min.js
- referencing pixi.min.js
- creating your PIXI Application instance.
- Point being:
- Window resize binding fucks up if the document isn't ready yet, specially in Chrome.
- Hence, we use jQuery here to ensure the document is in fact ready first,
before we actually bind that shit.
@joashp
joashp / openssl_encrypt_decrypt.php
Created September 4, 2015 15:59
Simple PHP encrypt and decrypt using OpenSSL
<?php
/**
* simple method to encrypt or decrypt a plain text string
* initialization vector(IV) has to be the same when encrypting and decrypting
*
* @param string $action: can be 'encrypt' or 'decrypt'
* @param string $string: string to encrypt or decrypt
*
* @return string
*/
@gerard-kanters
gerard-kanters / inactivity.js
Last active March 6, 2024 18:49
Inactivity timeout javascript
<script type="text/javascript">
function idleTimer() {
var t;
//window.onload = resetTimer;
window.onmousemove = resetTimer; // catches mouse movements
window.onmousedown = resetTimer; // catches mouse movements
window.onclick = resetTimer; // catches mouse clicks
window.onscroll = resetTimer; // catches scrolling
window.onkeypress = resetTimer; //catches keyboard actions
@austinhyde
austinhyde / js-observables-binding.md
Last active August 16, 2023 18:19
Vanilla JavaScript Data Binding

Observables

You don't really need a framework or fancy cutting-edge JavaScript features to do two-way data binding. Let's start basic - first and foremost, you need a way to tell when data changes. Traditionally, this is done via an Observer pattern, but a full-blown implementation of that is a little clunky for nice, lightweight JavaScript. So, if native getters/setters are out, the only mechanism we have are accessors:

var n = 5;
function getN() { return n; }
function setN(newN) { n = newN; }

console.log(getN()); // 5

setN(10);