Skip to content

Instantly share code, notes, and snippets.

Avatar
👨‍🍳
Cooking up great code

Nathan LeClaire nathanleclaire

👨‍🍳
Cooking up great code
View GitHub Profile
@nathanleclaire
nathanleclaire / gist:3688204
Created Sep 10, 2012
Learn Node The Troll Way
View gist:3688204
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 Oct 9, 2012
Node Reddit api login and comment
View gist:3859251
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 ...
View gist:3860215
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 Dec 11, 2015
I figured out the answer to this question :)
View Interval Shenanigans
<!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>
View README.md
View gist:5328747
// 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 Dec 28, 2015
Originally a JS Fiddle I put together that I'm making as a gist for reference
View PWM With JavaScript
<!doctype html>
<html>
<head>
<style>
p {
-webkit-transition: color 4s ease-in-out;
font-size: 72px;
}
p.greenit {
View RevisedConcatMapDoc.md

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 Feb 24, 2016
More terse, technical definition of how to send emails using Golang.
View SendingEmailsWithGolang.md

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 Aug 29, 2015
This will take in a Sudoku possible solution as a string and validate it.
View sudokuSolutionValidator.js
var solutions = [
'192356847643817952875429631584173296761592384239684175458231769926748513317965428',
'359784612821369745764251839247893561698517324513426987485932176976148253132675498',
'359784612821369745764251839547823961698517324213496587485932176976148253132675498'
];
function isValidSolution(grid) {
if (typeof grid !== 'string' || grid.length !== 81) {
return false;
} else {