Skip to content

Instantly share code, notes, and snippets.

View sodabear's full-sized avatar

James Jing sodabear

View GitHub Profile
@Wang-Kai
Wang-Kai / ladon_vs_casbin.md
Last active April 29, 2024 10:40
ladon & casbin 两个 authorization 库的比较

通览了 casbin 的文档,结合先前对 AWS IAM 的理解,以及对 ladon SDK 的使用,总结对比一下 Ladon & Casbin 两个授权库。

1. 项目定位

先对比两个项目的简介:

ladon

A SDK for access control policies: authorization for the microservice and IoT age. Inspired by AWS IAM policies. Written for Go.

@fditraglia
fditraglia / collapse_3darray.R
Created August 22, 2016 18:17
A simple example of how to collapse a 3d array into a matrix in R
# ------------------------------------------------------------------------------
# Here's a simple but slightly confusing task in R: collapsing a 3d array into a
# matrix. Specifically, we want to convert a 3d array of this form:
# ------------------------------------------------------------------------------
# , , 1
#
# [,1] [,2] [,3]
# [1,] "1.1.1" "1.2.1" "1.3.1"
# [2,] "2.1.1" "2.2.1" "2.3.1"
#
@cangoal
cangoal / ReservationManager.java
Created February 22, 2016 22:04
Design a reservation system for restaurant
public class ReservationManager {
List<Reservation> reservations;
List<Table> tables;
Set<Customer> customers;
private static ReservationManager instance;
private ReservationManager(){
customers = new HashSet<>();
init();

###回文分割分析

####原题 对一个字符串按照回文进行分割,例如aba|b|bbabb|a|b|aba就是字符串ababbbabbababa的一个回文分割,每一个字串都是一个回文。请找到可以分割的最少的字串数。例如:

  1. ababbbabbababa最少4个字符串,分割三次:a|babbbab|b|ababa
  2. 如果字符串整体是回文,则需要0次分割,最少1个字符串

####分析 这个题目很多做过leetcode的同学都见过,所以很多同学直接回复了DP。不过还是建议大家动手写一写。熟能生巧的。那么该如何分析这个题目呢?

@fditraglia
fditraglia / inflation_survey_weight.R
Created May 17, 2013 21:31
Naive Weighted Inflation Forecast
library(Quandl)
p <- 100 * Quandl('FRED/GDPDEF', collapse = 'quarterly', start_date = '1960-01-01', end_date = '2012-01-01', type = 'ts', transformation = 'rdiff')
#Michigan Inflation Expectations aren't in Quandl yet
library(quantmod)
getSymbols("MICH",src="FRED")
#Median expected price change next 12 months, Survey of Consumers.
#Convert to ts object
MICH.start <- as.numeric(format.Date(start(MICH), '%Y'))
@DiegoSalazar
DiegoSalazar / validate_credit_card.js
Last active April 24, 2024 12:51
Luhn algorithm in Javascript. Check valid credit card numbers
// Takes a credit card string value and returns true on valid number
function valid_credit_card(value) {
// Accept only digits, dashes or spaces
if (/[^0-9-\s]+/.test(value)) return false;
// The Luhn Algorithm. It's so pretty.
let nCheck = 0, bEven = false;
value = value.replace(/\D/g, "");
for (var n = value.length - 1; n >= 0; n--) {
@tonious
tonious / hash.c
Last active June 21, 2024 00:57
A quick hashtable implementation in c.
/* Read this comment first: https://gist.github.com/tonious/1377667#gistcomment-2277101
* 2017-12-05
*
* -- T.
*/
#define _XOPEN_SOURCE 500 /* Enable certain library functions (strdup) on linux. See feature_test_macros(7) */
#include <stdlib.h>
#include <stdio.h>
@kennethreitz
kennethreitz / 0_urllib2.py
Created May 16, 2011 00:17
urllib2 vs requests
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib2
gh_url = 'https://api.github.com'
req = urllib2.Request(gh_url)
password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm()