Skip to content

Instantly share code, notes, and snippets.

View gyuchang's full-sized avatar

Gyuchang Jun gyuchang

View GitHub Profile
@gyuchang
gyuchang / read_session_by_id.rb
Created April 23, 2020 18:32
Reading Rails Session from CacheStore
# config.cache_store = :redis_cache_store, { url: ENV['REDIS_URL'] }
# config.session_store = :cache_store
env = ActionDispatch::Request.new({})
app = Rails.application
sid = Rack::Session::SessionId.new(session_id)
store = ActionDispatch::Session::CacheStore.new(app)
_, session = store.find_session(env, sid)

Keybase proof

I hereby claim:

  • I am gyuchang on github.
  • I am gyuchang (https://keybase.io/gyuchang) on keybase.
  • I have a public key whose fingerprint is 2CFA 2248 C7C9 4E68 8784 1171 BC19 2164 68AB 4578

To claim this, I am signing this object:

@gyuchang
gyuchang / http.php
Created January 26, 2013 00:13
simple wrapper class for cURL
<?php
/*
* HTTP/HTTPS class: simple HTTP client
* - it's a wrapper for cURL, geared toward API/server-to-server call
* - if you want to mimic a browser, you should NOT use these classes
*/
class HTTP {
const SCHEME = 'http';
@gyuchang
gyuchang / locallock.php
Created November 29, 2011 22:18
Achieving local mutex via a lock file
<?php
class LocalLock {
const CONST_IO_TIMEOUT = 2; // in sec, 2 sec
const CONST_IO_SLEEP = 50000; // in usec, 50 msec
public static $base = '/tmp';
public static $debug = false;
private static $_lockfiles = array();
@gyuchang
gyuchang / purge_stale_lock.sh
Created November 29, 2011 18:49
Achieving local mutex via a lock file
#!/bin/bash
exec 0>&- # close stdin
exec 1>&- # close stdout - comment out this line to see debug message
exec 2>&- # close stderr
base='/tmp'
list=`find $base -type f -name '*.lock' -print 2>/dev/null`
for lockfile in $list; do
@gyuchang
gyuchang / locallock.php
Created November 29, 2011 18:40
Achieving local mutex via a lock file
<?php
class LocalLock {
const CONST_IO_TIMEOUT = 2; // in sec, 2 sec
const CONST_IO_SLEEP = 50000; // in usec, 50 msec
public static $base = '/tmp';
public static $debug = false;
private static $_lockfiles = array();
@gyuchang
gyuchang / Makefile
Created May 27, 2011 06:00
chkpasswd
all: chkpasswd.c
gcc -o chkpasswd -l crypt chkpasswd.c
install: all
install -s -m 4755 chkpasswd /usr/local/bin