Skip to content

Instantly share code, notes, and snippets.

View yorkie's full-sized avatar
🎯
Focusing

Yorkie Makoto yorkie

🎯
Focusing
View GitHub Profile
@yorkie
yorkie / async_uv.cc
Created November 8, 2013 06:50
async nodejs c++ addon
#include <v8.h>
#include <node.h>
#include <stdlib.h>
#include <errno.h>
using namespace node;
using namespace v8;
struct Test_req
{
@yorkie
yorkie / compare.js
Created November 14, 2013 08:42
check the same elements from 2 arrays.
// check the same elements from 2 arrays.
function compare(a, b){
var set = [];
var i = 0, j = 0;
var jHit = -1;
while (i < a.length && j < b.length) {
if (a[i]==b[j]){
set.push(a[i]);

Sublime Text 2 - Useful Shortcuts

Tested in Mac OS X: super == command

Open/Goto


  • super+t: go to file
  • super+ctrl+p: go to project
  • super+r: go to methods

‘Because’ has become a preposition, because grammar

If the title of this post made perfect sense to you, then you’re way ahead of me. But just in case, we’d best recap. Neal Whitman wrote a good article at Grammar Girl recently on the possible origins of because as a standalone preposition. This helpful passage from Whitman sets out the context:

In Standard English, the word “because” can be used two ways. One of them is to introduce a clause, as in “Aardvark was late because he was waiting for the repairman to show up.” Used this way, “because” is a subordinating conjunction. The other is to team up with “of” to form what’s called a compound preposition. For example, “Aardvark was late because of heavy traffic.” In the past three or four years, though, a new usage for “because” has been developing.

The new usage – older than 3–4 years, mind – is what Laura Bailey and Mark Liberman, respectively, have referred to as “because+noun” and “because NOUN”. Liberman says the idiom usually seems to imply “that

@yorkie
yorkie / fetch.js
Last active December 29, 2015 12:59
a simple imap connector for fetching...
var tls = require('tls');
var hostname = 'imap.qq.com';
var port = 993;
var option = {
rejectUnauthorized: false
}
var cleartextStream = tls.connect(port, hostname, option);
var step = 0;
@yorkie
yorkie / update.sh
Last active December 29, 2015 17:19
update the kernel params in linux...
echo 1 > /proc/sys/net/ipv4/tcp_tw_recycle
echo 1 > /proc/sys/net/ipv4/tcp_tw_reuse
service network restart
# vi-style
vi /etc/sysctl.conf
/sbin/sysctl -p // this command is for saving result
@yorkie
yorkie / 27.js
Last active December 30, 2015 03:49
quick tcp connection
exports.port = 10010;
var net = require('net');
var tls = require('tls');
var j = 0;
var k = 0;
function createTCP () {
var start = Date.now();
@yorkie
yorkie / r_recv.c
Last active December 30, 2015 11:19
a more geek function for the socket/recv in c
char *imap_recv(int fd, size_t size) {
size_t cursor = 0;
int rc;
char *buffer = (char *)malloc(sizeof(char)*size);
char *result = (char *)malloc(sizeof(char)*size);
while (rc = recv(fd, buffer, size, 0)) {
// if a message is less than the current size, it will return more data for fill in this pool. so I use \0 to avoid it.
buffer[rc] = '\0';
@yorkie
yorkie / benchmark.js
Created December 7, 2013 05:19
benchmark for array.join and +
function plus(count) {
var s = 'apple';
var start = Date.now();
var result = '';
for (var i=0; i<count; i++) result += s;
console.log(Date.now()-start)
}
function concat(count) {
var s = 'apple';
@yorkie
yorkie / simple-imap-client.c
Last active June 23, 2024 01:11
a simple imap client in C
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <pthread.h>
#include "uv.h"