Skip to content

Instantly share code, notes, and snippets.

package main
import "fmt"
import "time"
func main() {
timestart := time.Now()
for c := 0; c < 100000000; c++ {
@jaxbot
jaxbot / callback-equivalent.js
Last active August 29, 2015 14:05
Node.js generators vs. callbacks
function home() {
db.query("SELECT * FROM `posts` ORDER BY `time` DESC LIMIT 10", function(err, rows){
render('home', { posts: rows[0] }, function(err, result){
response.end(result);
});
});
}
function post(id) {
db.query("SELECT * FROM `posts` WHERE `link` = " + db.escape(id)), function(err, rows){
var koa = require('koa');
var route = require('koa-route');
var serve = require('koa-static');
var db = require('./db');
var render = require('./render');
var app = koa();
app.use(serve('public/'));
#include <stdio.h>
#include <stdlib.h>
#define true 1
#define false 0
int main(void) {
int ptr = 4;
int feelings = (ptr + 1) ? true : false;
function *create() {
//this.body = yield render('submit', { referer: this.request.headers.referer, key: key || '' });
var results = yield db.query("INSERT INTO `posts` (bla, bla) VALUES (bla, bla)");
console.log(results);
this.response.end(); //redirect('/post/' + results[0][0].link);
}
#!/bin/bash
# Log in to Carwings web interface
curl --data "j_username=$LEAF_USERNAME&j_passwordHolder=Password&j_password=$LEAF_PASSWORD" -c cookiejar.tmp https://www.nissanusa.com/owners/j_spring_security_check
# Request a status update
curl -b cookiejar.tmp https://www.nissanusa.com/owners/vehicles/statusRefresh?id=$LEAF_CARID
# Download status JSON (sync, blocking)
curl -b cookiejar.tmp https://www.nissanusa.com/owners/vehicles/pollStatusRefresh?id=$LEAF_CARID
{
"authLastModifiedDate": "2014-08-16T19:11:54Z",
"authToken": "[redacted]",
"chargeRequestDate": null,
"chargeTime": "15 hrs 30 min ",
"chargeTime220": "5 hrs 30 min ",
"chrgDrtn22066Tx": "4 hrs 0 min ",
"class": "com.nissanusa.owners.VehicleCarwings",
"currentBattery": 4,
"currentCharging": "NOT_CHARGING",
@jaxbot
jaxbot / Vim autocmds
Last active September 3, 2023 11:37
Vim MacBook LEDs
" Assuming keyboard_leds is built and available in your PATH,
" this will make capslock indicate whether or not you are in insert mode.
autocmd InsertEnter * :!keyboard_leds -c1
autocmd InsertLeave * :!keyboard_leds -c0
" To make Vim control the keyboard backlight, use this.
" Note that it's glitchy and you'll probably toss the idea soon after.
" I can see programmatically controlling the lights to be useful in other cases, though.
" Install Lab tick and set a hotkey for Toggle, and one for Brighten.
" http://labtick.proculo.de/
<!doctype html>
<html>
<head>
<script src='https://www.google.com/recaptcha/api.js'></script>
</head>
<body>
<h1>Register for test site</h1>
<form action="register" method="post">
<input type="text" name="username" placeholder="Username"><br>
@jaxbot
jaxbot / form.html
Last active January 13, 2019 14:11
Node.js recaptcha example 2 (using AJAX instead of forms) https://jaxbot.me/articles/new-nocaptcha-recaptcha-with-node-js-express-12-9-2014
<!doctype html>
<html>
<head>
<script src='https://www.google.com/recaptcha/api.js'></script>
<script>
function registerAPI(form) {
var params = {
username: form.username.value,
password: form.password.value,
email: form.email.value,