Skip to content

Instantly share code, notes, and snippets.

View automactic's full-sized avatar

ChrisLi automactic

View GitHub Profile
@automactic
automactic / SearchTabController.swift
Last active June 20, 2016 18:58
iOS parallax scroll effect using UIScrollView + children controllers
//
// SearchTabController.swift
// PageViewController
//
// Created by Chris Li on 3/31/16.
// Copyright © 2016 Chris Li. All rights reserved.
//
import UIKit
var navBarOriginalHeight: CGFloat = 0.0
let navBarMinHeight: CGFloat = 10.0
var previousScrollViewYOffset: CGFloat = 0.0
// MARK: - UIScrollViewDelegate
func scrollViewDidScroll(scrollView: UIScrollView) {
guard scrollView.contentSize.height >= scrollView.frame.height else {return}
guard let navigationBar = navigationController?.navigationBar else {return}
@automactic
automactic / UICollectionView+FetchedResultControllerDelegate.swift
Last active January 17, 2017 16:06
Swift 3 UICollectionView FetchedResultControllerDelegate
class Controller: UIViewController, NSFetchedResultsControllerDelegate {
private var closures = [() -> Void]()
let managedObjectContext = AppDelegate.persistentContainer.viewContext
lazy var fetchedResultController: NSFetchedResultsController<Article> = {
}()
func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChange anObject: Any, at indexPath: IndexPath?, for type: NSFetchedResultsChangeType, newIndexPath: IndexPath?) {
switch type {
case .insert:
@automactic
automactic / gist.md
Last active March 3, 2017 15:49
Celery Startup

start RabbitMQ rabbitmq-server

start Celery with detail task info celery -A api.celery worker --loglevel=info

Celery flowers celery -A api.celery flower

flask & mongo

@automactic
automactic / gist:37c72ee3e3f85943a4d07915007d83cd
Last active March 21, 2017 13:28
XOR checksum of [0, n]

Input:

val = 0
for i in range(0, 100):
    val ^= i
    print("{}, {}".format(i, val))

Output:

@automactic
automactic / question.md
Last active March 21, 2017 21:29
A question

I have a db connection, which need configuration. I want to use this connection in all flask apis. So normally I would do it like this:

app = Flask(__name__)
db = Database(config_obj)

@app.route('/')
def hello():
    # a lot of code
    username = db.get_data()
 return 'Hello, {}!'.format(username)
@automactic
automactic / proposal.md
Last active April 28, 2017 04:55
Zimfarm task proposal
  • Forget about the concept of templates
  • We create tasks directly from a json uploaded by admin, which is an array of task objects. The task object looks like below.
  • Every time admin upload a new json, all executing tasks continues, all already scheduled tasks get cancelled, system is populated with tasks from new json. (We can further discuss the strategy used here)
  • Database only keeps task execution history, including what is the command being executed, when task started / finished, which worker executed it, and if success or not
{
    "id": "12345-67890-qwerty",
    "command": "./build_zim.sh -args",
    "scheduling": {
 "repeat": true,
import { Component, OnInit, OnDestroy } from '@angular/core';
import { Observable, Subscription } from 'rxjs/Rx';
import { Task } from '../../model/task';
@Component({
selector: 'tasks',
templateUrl: './list-tasks.component.html',
styleUrls: ['./list-tasks.component.css']
})
import { Component, OnInit, OnDestroy } from '@angular/core';
import { Observable, Subscription } from 'rxjs/Rx';
import { Task } from '../../model/task';
@Component({
selector: 'tasks',
templateUrl: './list-tasks.component.html',
styleUrls: ['./list-tasks.component.css']
})
@automactic
automactic / gist:3af58ee5ada0279518f802e31c601888
Last active July 28, 2017 18:35
Zimfarm useful commands
# stop all dispatcher containers
docker stop $(docker ps -q --filter "label=com.chrisshwli.zimfarm.name")
# run all dispatcher containers
docker-compose up --build -d
# run worker
docker build -t worker . && docker run -v /var/run/docker.sock:/var/run/docker.sock worker
docker run --link=zimfarm-worker-redis:redis openzim/mwoffliner mwoffliner --mwUrl=https://en.wikipedia.org/ --adminEmail=foo@bar.net