Skip to content

Instantly share code, notes, and snippets.

@weilu
weilu / index.js
Last active December 8, 2021 19:13
Offset based pagination with Django, graphene, Apollo and react
import ReactDOM from 'react-dom';
import React, { useState, useCallback, useEffect } from 'react';
import { useQuery } from '@apollo/client';
import { gql } from '@apollo/client';
const CASE_FIELDS = `
id
referralDate
caseNumber
@weilu
weilu / semver-ranges.md
Last active August 29, 2015 14:03
Much Semver, Such Confusion

Rubygem's ~> pessimistic / eat beacon / spermy operator

Keep first n-1 digits the same, last digit is free to increment to some arbitrary value

~>1:      >=1.0.0 <2.0.0
~>1.0:    >=1.0.0 <2.0.0
~>1.2.3:  >=1.2.3 <1.3.0
~>0.1:    >=0.1.0 <1.0.0
~&gt;0.1.3: &gt;=0.1.3 &lt;0.2.0
@weilu
weilu / expressParseCookie.js
Created June 11, 2014 01:57
express.js: test cookie content
var cookieParser = require('express').cookieParser(process.env.COOKIE_SALT)
function parseCookie(cookie){
var fakeReq = {headers: {cookie: cookie}}
cookieParser(fakeReq, null, function(){
console.log(fakeReq)
})
}
parseCookie("connect.sid=s%3A70TTUUz60sHREcMcDsBuTWBf.2vKZjdW%2B2ecr%2Bk8kI%2Frno%2BoqdQmSPHFuz1g4V7OJzSM; Path=/; HttpOnly")
@weilu
weilu / auth.js
Last active August 20, 2019 15:35
Cloudant create user
var cradle = require('cradle');
var crypto = require('crypto');
cradle.setup({
host: 'foo.cloudant.com',
port: 80,
cache: false,
timeout: 5000
})
@weilu
weilu / 0_reuse_code.js
Created March 18, 2014 05:42
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@weilu
weilu / moment-timezone-data.js
Created March 18, 2014 05:09
sample moment-timezone-data.js
// generated on http://momentjs.com/timezone/data/
// Selected timezones: Asia > All, America > All, Europe > All
moment.tz.add({
"zones": {
"America/Adak": [
"12:13:21 - LMT 1867_9_18 12:13:21",
"-11:46:38 - LMT 1900_7_20_12 -11:46:38",
"-11 - NST 1942 -11",
"-11 US N%sT 1946 -11",
@weilu
weilu / README.md
Last active October 9, 2020 15:55
World Clock widget for dashing

World Clock

screen shot 2013-11-28 at 12 29 37 pm

Description

A simple widget that's capable of displaying time for multiple locations around the world. In our company(neo), we use it to display time in different offices.

Installation

@weilu
weilu / README.md
Created November 28, 2013 03:47 — forked from melekes/README.md

Yet another Google Calendar Dashing widget

Yet another Google Calendar Dashing widget

Description

Dashing widget to display first two coming-up Google Calendar events.

Basically, you do not need more than two events on your dashboard, but it can be easily extended to the neighboring cells and show, say, 4 events instead of 2.

@weilu
weilu / controller-example-group.rb
Last active December 26, 2015 05:59
Never forget to make requests in controller specs
# spec/support/rspec-rails/controller-example-group.rb
module RSpec::Rails
module ControllerExampleGroup
def process *args
@requested = true
super
end
def self.included(base)
require "active_record"
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
ActiveRecord::Schema.define do
create_table :languages do |t|
t.string :type
end
end