Skip to content

Instantly share code, notes, and snippets.

Avatar

nitrag

  • Atlanta, GA
View GitHub Profile
@treyhunner
treyhunner / choice_enum.py
Created Apr 9, 2018
Enum for use with Django ChoiceField
View choice_enum.py
from enum import Enum, EnumMeta
class ChoiceEnumMeta(EnumMeta):
def __iter__(self):
return ((tag, tag.value) for tag in super().__iter__())
class ChoiceEnum(Enum, metaclass=ChoiceEnumMeta):
"""
@nitrag
nitrag / check_mk_agent-ubuntu-install.sh
Created Mar 6, 2018
Setup check_mk_agent via systemd on Ubuntu 16.04 (OMD, Check_MK)
View check_mk_agent-ubuntu-install.sh
# How to install Check MK Agent on ubuntu 16.04
# Install check_mk_agent:
# - sudo apt-get install check-mk-agent (will install older version)
# - On your Check_MK dashboard, go to "Monitoring Agents", click the link for "Check_MK Agent for Linux", save the raw text
# on your server:
sudo vi /usr/bin/check_mk_agent
# paste Check_MK dashboard > Monitoring Agents > Check_MK Agent for Linux
@droberin
droberin / fix_avatars.py
Created Feb 9, 2018
Slack exported conversation avatar replacement with locally downloaded avatars from original URL
View fix_avatars.py
import os
import lxml.html as LH
import shutil
import requests
temp_dir = "/tmp/avatar_tmp"
if not os.path.isdir("html/avatars"):
os.mkdir("html/avatars")
if os.path.isdir(temp_dir):
@vinhnx
vinhnx / uicollectionview+snap.md
Last active Mar 8, 2020
UICollectionView snap onto cell when scrolling horizontally
View uicollectionview+snap.md

// reference: https://stackoverflow.com/a/43637969/1477298

While originally I was using Objective-C, I since switched so Swift and the original accepted answer did not suffice.

I ended up creating a UICollectionViewLayout subclass which provides the best (imo) experience as opposed to the other functions which alter content offset or something similar when the user has stopped scrolling.

class SnappingCollectionViewLayout: UICollectionViewFlowLayout {

    override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint, withScrollingVelocity velocity: CGPoint) -> CGPoint {
@boundsj
boundsj / example_swift_geojson_clustering_filters.md
Created Sep 26, 2016
Swift GeoJSON + Clustering + Filters Example
View example_swift_geojson_clustering_filters.md
    func mapViewDidFinishLoadingMap(_ mapView: MGLMapView) {
        let source = MGLSource(sourceIdentifier: "source")!
        
        let symbolLayer = MGLSymbolStyleLayer(layerIdentifier: "place-city-sm", source: source)
        let url = URL(string: "https://www.mapbox.com/mapbox-gl-js/assets/earthquakes.geojson")!
        let options = [MGLGeoJSONClusterOption: NSNumber(booleanLiteral: true),
                       MGLGeoJSONClusterRadiusOption: NSNumber(integerLiteral: 20),
                       MGLGeoJSONClusterMaximumZoomLevelOption: NSNumber(integerLiteral: 15)]
        let geoJSONSource = MGLGeoJSONSource(sourceIdentifier: "earthquakes", url: url, options: options)
@ipbastola
ipbastola / clean-up-boot-partition-ubuntu.md
Last active Aug 13, 2020
Safest way to clean up boot partition - Ubuntu 14.04LTS-x64, Ubuntu 16.04LTS-x64
View clean-up-boot-partition-ubuntu.md

Safest way to clean up boot partition - Ubuntu 14.04LTS-x64, Ubuntu 16.04LTS-x64

Reference

Case I: if /boot is not 100% full and apt is working

1. Check the current kernel version

$ uname -r 
@cpmpercussion
cpmpercussion / loop_pi_video.sh
Created Jul 15, 2016
omxplayer command to loop a video forever for use in video art exhibitions
View loop_pi_video.sh
#!/bin/bash
# This one-liner script plays a video in an infinite loop on a raspberry pi
# for a video-art exhibition.
# It was written for a video in portrait orientation so the video is rotated 270
# to use up the whole screen (which was also rotated).
# Charles Martin, July 2016
omxplayer -o local --loop /home/pi/video.mp4 --orientation 270
View PHPhotoLibrary+PhotoAsset.swift
extension PHPhotoLibrary {
typealias PhotoAsset = PHAsset
typealias PhotoAlbum = PHAssetCollection
static func saveImage(image: UIImage, albumName: String, completion: (PHAsset?)->()) {
if let album = self.findAlbum(albumName) {
saveImage(image, album: album, completion: completion)
return
}
@flovilmart
flovilmart / Example.swift
Created Feb 17, 2016
Authenticate with custom OAuth example
View Example.swift
import Parse
import Bolts
class AuthDelegate:NSObject, PFUserAuthenticationDelegate {
func restoreAuthenticationWithAuthData(authData: [String : String]?) -> Bool {
return true
}
}
let configuration = ParseClientConfiguration { (configuration) -> Void in
You can’t perform that action at this time.