Skip to content

Instantly share code, notes, and snippets.

@pragmaticlogic
pragmaticlogic / main.jsx
Last active August 29, 2015 14:21
onSearchClick
var onSearchClick = ((event) => {
//Impure
var element = this.refs.searchText.getDOMNode()
var focusElement = element => { element.value = ''; element.focus() }
var showResult = element => { Navigate(`/dashboard/${element.value}`) }
//Pure
var getInput = element => element.value
var isInputEmpty = R.eq('')
var checkInput = R.compose(isInputEmpty, R.trim, getInput)
@pragmaticlogic
pragmaticlogic / main.jsx
Last active August 29, 2015 14:21
render
var Main = React.createClass({
render() {
// nothing above here
// anonymous function is immediately invoked
return ((context, props, state) => {
//quarantine impure code
//....
//....
//event handler code
//onKeyDownHandler = ...
@pragmaticlogic
pragmaticlogic / main.jsx
Last active August 29, 2015 14:21
skeleton
var Main = React.createClass({
render() {
// nothing above here
// anonymous function is immediately invoked
return ((context, props, state) => {
//quarantine impure code
//....
//....
//pure code
//....
<!DOCTYPE html>
<html>
<head>
<script src="http://cdnjs.cloudflare.com/ajax/libs/ramda/0.13.0/ramda.min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
@pragmaticlogic
pragmaticlogic / gist:c6171ee75338f0398f19
Last active August 29, 2015 14:17
Transpose array using ES6 syntax and Ramda.js
var transpose = a => {
return R.map(c => {
return R.map(r => {
return r[c];
}, a);
}, R.keys(a[0]));
};
var a = [
[1,2,3,4],
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery.min.js"></script>
<link href="http://getbootstrap.com/dist/css/bootstrap.css" rel="stylesheet" type="text/css" />
<script src="http://getbootstrap.com/dist/js/bootstrap.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
<style id="jsbin-css">
/* adjust body when menu is open */
@pragmaticlogic
pragmaticlogic / node-apps-startup.sh
Last active September 4, 2020 14:58
node-apps-startup.sh
#!/bin/bash
#
# An init.d script for running a Node.js process as a service using iptables, forever and bouncy
# Reference:
# 1- https://github.com/nodejitsu/forever
# 2- https://www.exratione.com/2013/02/nodejs-and-forever-as-a-service-simple-upstart-and-init-scripts-for-ubuntu/
source /home/kle/.nvm/nvm.sh
NAME="Script for all NodeJS apps"
NVM_VERSION="v0.10.31"
internal class TokenValidationHandler : DelegatingHandler
{
// This function retrieves ACS token (in format of OAuth 2.0 Bearer Token type) from
// the Authorization header in the incoming HTTP request from the client.
private static bool TryRetrieveToken(HttpRequestMessage request, out string token)
{
try
{
token = null;
IEnumerable<string> authHeaders;

###Expose IIS or IISExpress running in a Parallels Windows 7/8 VM to your OS X host

####Rename your virtual machine In your Windows 7/8 VM, go to Control Panel > System > Advanced system settings > Computer Name and click Change. Name this whatever you like, e.g. windows. Restart your VM.

####Add an ACL rule Open CMD or Powershell as administrator. Add a URL ACL entry for your new name on the port of your choice, e.g.
netsh http add urlacl url=http://windows:8080/ user=everyone

####Add a firewall rule

@pragmaticlogic
pragmaticlogic / SwiftTowerTestInteractive
Created October 20, 2014 18:53
Swift Tower Test Interactive
func checkTower(dest:Stack<Int>, numberOfDisks:Int) -> Bool {
var match = true
var index = 1
while match && dest.size() > 0 && index <= numberOfDisks {
match = dest.pop() == index
index++
}
return match
}