Skip to content

Instantly share code, notes, and snippets.

@usmanity
usmanity / app.js
Last active Jul 13, 2020
Use the following for being able to safely get body content from HTTP requests, set the view engine (change to your liking), and displaying static content
View app.js
// create an express app (import express first)
const app = express();
// tell app to use bodyParser, I believe this still needs to be imported but it's installed with express last I checked
// bodyParser will help keep your incoming http POST body clean
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
// set the view engine to be pug ONLY if you want a view engine
// if you're displaying static content in vue.js or React, you can just let it be HTML
@usmanity
usmanity / move.js
Last active Nov 9, 2019
move to the next page
View move.js
/* this version wasn't working
$(document).on('keydown', function(e) {
if (e.key == "ArrowRight" || e.key == " ") {
let next = $('a').filter((b, anchor) => $(anchor).text().includes('next') )
next.click();
}
});
*/
// working version
View Blockstack
Verifying my Blockstack ID is secured with the address 13LDAQ1kgtKivD4DxUVeWQrAV3kogTrtLB https://explorer.blockstack.org/address/13LDAQ1kgtKivD4DxUVeWQrAV3kogTrtLB
@usmanity
usmanity / docker-compose.yml
Created Nov 26, 2017
Example of a docker compose file
View docker-compose.yml
version: "3"
services:
web:
image: usmanity/friendlyhello:part2
deploy:
replicas: 2
resources:
limits:
cpus: "0.1"
memory: 50M
@usmanity
usmanity / loading.py
Created Apr 4, 2017
loading indicator in python for CLI tools
View loading.py
while True:
for i in ["/", "-", "|", "\\", "|"]:
print "%s\r" % i,
@usmanity
usmanity / fibonacci.js
Created Aug 6, 2015
fibonacci sequence in javascript
View fibonacci.js
function fib(x){
if (x == 0 || x == 1) {
return 1;
} else {
return fib(x-1) + fib(x-2);
}
}
@usmanity
usmanity / palindrome.js
Created Aug 6, 2015
a simple gist for finding a palindrome in javascript
View palindrome.js
function isPalindrome(p){
if (p.length == 0 || p.length == 1) {
return true;
} else if (p[0] == p[p.length - 1]) {
return isPalindrome(p.slice(1, p.length - 1));
} else {
return false;
}
}
@usmanity
usmanity / color.js
Created Jan 9, 2015
colors.js back up for later
View color.js
var getDailyHex = function(){
var d = new Date();
var month = (d.getMonth() + 1).toString();
var day = function(){ if (d.getDate() < 10) { return '0' + d.getDate() } return d.getDate().toString() };
var year = (d.getFullYear() - 2000).toString();
var dailyHex = month + day() + year;
return dailyHex;
}
var getSecondsHex = function(){
@usmanity
usmanity / prime
Created Dec 30, 2014
prime in python
View prime
# http://stackoverflow.com/questions/18833759/python-prime-number-checker
import math
def is_prime(n):
if n % 2 == 0 and n > 2:
return False
return all(n % i for i in range(3, int(math.sqrt(n)) + 1, 2))
View year
<script type="text/javascript">
document.write(new Date().getFullYear());
</script>