Skip to content

Instantly share code, notes, and snippets.

View nathanleclaire's full-sized avatar
👨‍🍳
Cooking up great code

Nathan LeClaire nathanleclaire

👨‍🍳
Cooking up great code
View GitHub Profile
@nathanleclaire
nathanleclaire / gist:3688204
Created September 10, 2012 00:49
Learn Node The Troll Way
var jsdom = require('jsdom');
var request = require('request');
var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database('/home/nathan/webdev/learnnodethetrollway/db/nodetroll.db');
var util = require('util');
// Way to have no class, Nate
var CHARACTERS = {
@nathanleclaire
nathanleclaire / gist:3859251
Created October 9, 2012 14:41
Node Reddit api login and comment
request.post({url: 'http://www.reddit.com/api/login',
qs: {
username: 'nate',
passwd: 'meta',
api_type: 'json'
}},
function(error, response, body) {
if (!error && response.statusCode === 200) {
// var mod_hash = body.whatever;
// etc ...
var TrollBot = {
mod_hash: undefined,
postComment: function(to_username, text) {
if (!mod_hash) {
// just wait a second
setTimeout(this.postComment, 1000);
} else {
request.post( //.....blah blah blah
);
@nathanleclaire
nathanleclaire / Interval Shenanigans
Last active December 11, 2015 06:19
I figured out the answer to this question :)
<!doctype html>
<html>
<head>
<title>Interval Shenanigans</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<style>
input {
margin: 20px;
}
</style>
// Copyright 2010 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"html/template"
"io/ioutil"
"net/http"
@nathanleclaire
nathanleclaire / PWM With JavaScript
Last active December 28, 2015 08:59
Originally a JS Fiddle I put together that I'm making as a gist for reference
<!doctype html>
<html>
<head>
<style>
p {
-webkit-transition: color 4s ease-in-out;
font-size: 72px;
}
p.greenit {

RethinkDB: The concatMap command in Javascript


Description

The r.concatMap method applies a transformation (defined by the mappingFunction) to each document in the sequence of documents provided, then merges all of the sequences returned by the mappingFunction into a single sequence. This can be used to aggregate collections that are sprinkled across multiple documents for further processing.

Declaration

@nathanleclaire
nathanleclaire / SendingEmailsWithGolang.md
Last active February 24, 2016 19:21
More terse, technical definition of how to send emails using Golang.

Sending emails from Gmail Using Golang

Sending emails from a Gmail account using Go can be done using Go's smtp package. Simply:

  1. Connect to smtp.gmail.com on port 587, authenticating using your email and password
  2. Optionally, use Go's text/template package to format the To, From, Subject, and Body fields of your email
  3. Use smtp's SendMail method to actually send the email

An example usage follows. The SmtpTemplateData struct is used to hold the context for the templating mentioned in (2) above.

@nathanleclaire
nathanleclaire / sudokuSolutionValidator.js
Last active August 29, 2015 13:56
This will take in a Sudoku possible solution as a string and validate it.
var solutions = [
'192356847643817952875429631584173296761592384239684175458231769926748513317965428',
'359784612821369745764251839247893561698517324513426987485932176976148253132675498',
'359784612821369745764251839547823961698517324213496587485932176976148253132675498'
];
function isValidSolution(grid) {
if (typeof grid !== 'string' || grid.length !== 81) {
return false;
} else {