Skip to content

Instantly share code, notes, and snippets.

@peicheng
peicheng / id.go
Created May 9, 2018 16:43 — forked from jordanorelli/id.go
fast unique id generation in Go
package main
import (
"crypto/md5"
"encoding/binary"
"fmt"
"os"
"sync/atomic"
"time"
)
@peicheng
peicheng / InsertDate.gs
Created April 26, 2018 09:31 — forked from thomxc/InsertDate.gs
Google Docs Script Macro: Insert Date
/**
* The onOpen function runs automatically when the Google Docs document is
* opened. Use it to add custom menus to Google Docs that allow the user to run
* custom scripts. For more information, please consult the following two
* resources.
*
* Extending Google Docs developer guide:
* https://developers.google.com/apps-script/guides/docs
*
* Document service reference documentation:

steps:

  • you need to have node.js installed

  • copy main.js & package.json to a new folder

  • in the terminal:

    • to build it, run: npm install and then npm start

    • to pack it like a regular app, use 'electron-packager'. install it globally by running: npm install electron-packager -g

@peicheng
peicheng / generate-pushid.js
Created December 26, 2016 10:50 — forked from mikelehen/generate-pushid.js
JavaScript code for generating Firebase Push IDs
/**
* Fancy ID generator that creates 20-character string identifiers with the following properties:
*
* 1. They're based on timestamp so that they sort *after* any existing ids.
* 2. They contain 72-bits of random data after the timestamp so that IDs won't collide with other clients' IDs.
* 3. They sort *lexicographically* (so the timestamp is converted to characters that will sort properly).
* 4. They're monotonically increasing. Even if you generate more than one in the same timestamp, the
* latter ones will sort after the former ones. We do this by using the previous random bits
* but "incrementing" them by 1 (only in the case of a timestamp collision).
*/
import random
import time
import numpy
from exceptions import ValueError
class PushID(object):
# Modeled after base64 web-safe chars, but ordered by ASCII.
PUSH_CHARS = ('-0123456789'
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
// To create a clone of pad CWrp961Hnw as of revision 3:
// http://sketchpad.cc/sp/pad/newsketch?clonePadId=CWrp961Hnw&cloneRevNum=3
// --------------------------------------------------------------------------------
// in etherpad/src/etherpad/control/pad/pad_control.js
// --------------------------------------------------------------------------------
import("etherpad.collab.collab_server.buildHistoricalAuthorDataMapForPadHistory");
# Index
---------------------------------------------------------------------
curl -XPUT http://localhost:9200/pictures/ -d '
{
"settings": {
"analysis": {
"analyzer": {
"index_analyzer": {
"tokenizer": "standard",
<?php
/**
* Translates a number to a short alhanumeric version
*
* Translated any number up to 9007199254740992
* to a shorter version in letters e.g.:
* 9007199254740989 --> PpQXn7COf
*
* specifiying the second argument true, it will
* translate back e.g.:
#! /bin/sh
#
# Logstash Start/Stop logstash
#
# chkconfig: 345 99 99
# description: Logstash
# processname: logstash
logstash_bin="java -Djava.net.preferIPv4Stack=true -jar /opt/logstash/logstash-1.0.11pre-monolithic.jar"
logstash_log="/opt/logstash/logstash-web.log"
@peicheng
peicheng / renren.py
Created February 4, 2012 07:33 — forked from taoyu/renren.py
download an album from renren.com
#change the two variables below as your need
#then, run python renren.py, you got it
#you also need an empty folder called "download"
data = (('email', '[email protected]'), ('password', '123456'), ('origURL', 'http://www.renren.com/Home.do'), ('domain', "renren.com"))
album_url = 'http://photo.renren.com/photo/249794035/album-484759819'
import cookielib