Skip to content

Instantly share code, notes, and snippets.

@gflarity
gflarity / helloworld.tsx
Created March 20, 2023 20:14
Using TSX/JSX files with Deno.
#!/usr/bin/env deno run
/** @jsxImportSource https://esm.sh/preact */
import { render } from "https://esm.sh/preact-render-to-string@5.2.6";
export function App() {
return (
<html lang="en">
<head>
<title>title</title>
run_termpilot () {
echo
deno run -A main.ts
zle reset-prompt
}
@gflarity
gflarity / file.ts
Created March 15, 2023 17:20
Some Deno code for reading a file a line by line asychronously
// function that returns reads a file line by line asynchronously
export async function* readFileLineByLine(file: string) : AsyncGenerator<string> {
const textDecoder = new TextDecoder();
let stringBuffer: string = "";
const fileHandle = await Deno.open(file);
try {
let intBuffer = new Uint8Array(1000);
let numberOfBytesRead = await fileHandle.read(intBuffer);
while (numberOfBytesRead !== null) {
const asString = textDecoder.decode(intBuffer);
@gflarity
gflarity / node-ec2-ubuntu-cluster
Created February 21, 2011 21:44
Node+cluster on Amazon EC2 Quickstart
#First you'll need to Signup for AWS/EC2 and generate a key pair. Google it, there should be plenty of
#tutorials.
#Next, create an instance using the AWS Management Console and log into it using your key pair.
#You can find the AMI's here https://help.ubuntu.com/community/EC2StartersGuide
#I picked a 64bit 10.04 LTS AMI in US-East.
#Install node's perquisites (or those that aren't the default ubuntu LTS ami):
sudo apt-get update
sudo apt-get install build-essential libssl-dev
@gflarity
gflarity / kiss.js
Created February 17, 2012 16:21
simple node.js based deployment tool
//each task gets executed in parallel across each host defined, each phase is executed serially
//support for running individual phases+tasks should be easy
phase( 'web' )
.host( 'a.domain.com' )
.host( 'b.domain.com' )
.config( 'foo', [ 1, 2, 3 ] )
.task( 'checkout code',
function( c )
{
function my_set( key, value ) {
index.set( key, value, function(err, context) {
if ( err ) {
console.log( err );
process.exit(0);
}
else {
console.log( "successfully inserted " + key );
}
var key = 'E18EFDFD-ACC4-42CB-8261-E8139886DA1C';
var value = 'foo';
index.set( key, value, function(err, context) {
if ( err ) {
console.log( err );
process.exit(0);
}
else {
console.log( "successfully inserted " + content.key );
}
@gflarity
gflarity / node-index-snippet1
Created March 29, 2011 00:05
node-index issues
// You can run this file again and again and it will:
// 1) Keep inserting the same keys over and over again
// 2) You can't no longer trust the variables outside of the callbacks passed to index.set, context is needed
var generate_uuid = require('node-uuid');
var index_file = 'data/test.index';
var index;
console.log('run it twice, it should fail the second time as it keeps adding keys as if they were new');
var on_index_created = function(err) {
if ( err ) {
console.log(err);
@gflarity
gflarity / gist:843783
Created February 25, 2011 13:36
Understanding Inheritance In JavaScript
This is a rough outline for an article
In this article I will present the JavaScript inerhitence model in a concise and I hope easy to understand manner. The intended audience consists of developers with some previous experience with dynamically typed languages. It is my opinion that any difficulty associated with understanding the JavaScript inheritance model can be attributed to the difficulty teaching recursive definitions in general. It's sometimes hard to know where to start, when your definition is circular.
That said, let's boil JavaScript inheritance down into 5 key points:
1) In JavaScript, everything is an 'object' and all variables simply hold references to them. The other 'primitive' or basic types (of objects) are functions, booleans, strings, numbers and arrays.
2) Objects are collections of properties keyed by a reference. Most often, references to string objects are used as keys as they are immutable. This means that if foo and bar reference string types which contain the same data they
@gflarity
gflarity / ssh-agent-forwarding-screen.md
Last active August 29, 2015 14:25 — forked from martijnvermaat/ssh-agent-forwarding-screen.md
SSH agent forwarding and screen

SSH agent forwarding and screen

When connecting to a remote server via SSH it is often convenient to use SSH agent forwarding so that you don't need a separate keypair on that server for connecting to further servers.

This is enabled by adding the

ForwardAgent yes

option to any of your Host entries in ~/.ssh/config (or alternatively with the -A option). Don't set this option in a wildcard Host * section since any user on the remote server that can bypass file permissions can now als use keys loaded in your SSH agent. So only use this with hosts you trust.