Skip to content

Instantly share code, notes, and snippets.

View glaszig's full-sized avatar

glaszig

  • available for hire. contact me.
  • remote
View GitHub Profile
@maxneuvians
maxneuvians / bucket.ex
Last active June 11, 2023 04:07
Leaky Bucket GenServer in Elixir
defmodule LeakyBucket.Bucket do
@moduledoc """
Simulates a leaky bucket implementation
"""
use GenServer
@initial_amount 0
@increment_rate 1
@leak_rate 2
@leak_interval 500
@dittoalex
dittoalex / s3_read_only_policy.json
Created June 13, 2017 18:45 — forked from ramhoj/s3_read_only_policy.json
AWS IAM S3 read/write only policy
{
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetBucketLocation",
"s3:GetObject",
"s3:ListBucket"
],
"Resource": [
@danielctull
danielctull / ReplaceSegue.swift
Created March 7, 2017 10:15
A simple NSStoryboardSegue to replace the last view controller in a NSSplitViewController.
import Cocoa
class ReplaceSegue: NSStoryboardSegue {
override func perform() {
guard
let source = sourceController as? NSViewController,
let new = destinationController as? NSViewController,
(function ($$) {
// Open a console in your web browser and paste
// this entire script into it. This script doesn't
// phone home at any point, you have to do that
// manually. Still, give it a read.
// `Cmd + Opt + J` on Chrome
var user;
@ecleel
ecleel / db_fixtures_dump.rake
Last active January 21, 2024 10:25 — forked from iiska/db_fixtures_dump.rake
Rails 5: Dump Rails db to fixtures
# Original from http://snippets.dzone.com/posts/show/4468 by MichaelBoutros
#
# Optimized version which uses to_yaml for content creation and checks
# that models are ActiveRecord::Base models before trying to fetch
# them from database.
namespace :db do
namespace :fixtures do
desc 'Dumps all models into fixtures.'
task :dump => :environment do
models = Dir.glob(Rails.root + 'app/models/**.rb').map do |s|
@mattwelke
mattwelke / operations_controller.rb
Created November 22, 2016 21:06
Async Controller Actions in Ruby on Rails
# Full repo:
# https://gitlab.com/mwelke/rails-async-example
Future = Concurrent::Future
class OperationController < ApplicationController
def sync
ops = [1, 2, 3]
ops.each do |n|
@mesuutt
mesuutt / chart.html
Last active March 23, 2021 02:08
Chart.js - Doughnut chart with custom legend http://codepen.io/mesuutt/pen/LbyPvr
<div class="canvas-con">
<div class="canvas-con-inner">
<canvas id="mychart" height="250px"></canvas>
</div>
<div id="my-legend-con" class="legend-con"></div>
</div>
@PaulChana
PaulChana / NSTaskAsyncOutput.mm
Created October 17, 2016 09:12
NSTask Async output to NSTaskView
NSMutableArray *arguments = [[NSMutableArray alloc] init];
[arguments addObject:[[NSBundle mainBundle] pathForResource:@"MyScript" ofType:@"py"]];
[arguments addObject:@"--verbose"]; // Any arguments you want here...
NSTask* task = [[NSTask alloc] init];
task.launchPath = @"/usr/bin/python";
task.arguments = arguments;
NSMutableDictionary *defaultEnv = [[NSMutableDictionary alloc] initWithDictionary:[[NSProcessInfo processInfo] environment]];
[defaultEnv setObject:@"YES" forKey:@"NSUnbufferedIO"] ;
@seckincengiz
seckincengiz / ExampleUsage.swift
Last active July 10, 2018 19:21 — forked from s-aska/Keychain.swift
Swift Keychain class ( supported Xcode 8.1 Beta and IOS 10.1 ) [swift3]
import UIKit
let scoresStringArray : [String] = ["Mike","Tom","Bily"]
let scoresDataArray = NSKeyedArchiver.archivedData(withRootObject: scoresStringArray)
//Save data
_ = Keychain.save(key: "scoresKey", data: scores)
//Load data
if Keychain.load(key: "scoresKey") != nil{
@mminer
mminer / PreferencesViewController.swift
Last active May 19, 2024 05:06
NSTabViewController for preferences window that resizes itself to fit activated tab view.
import AppKit
class PreferencesViewController: NSTabViewController {
private lazy var tabViewSizes: [NSTabViewItem: NSSize] = [:]
override func tabView(_ tabView: NSTabView, didSelect tabViewItem: NSTabViewItem?) {
super.tabView(tabView, didSelect: tabViewItem)
if let tabViewItem = tabViewItem {