Skip to content

Instantly share code, notes, and snippets.

View loiclefloch's full-sized avatar

Loïc Lefloch loiclefloch

View GitHub Profile
@loiclefloch
loiclefloch / change_brightness.sh
Last active August 29, 2015 14:08
Change keyboard brightness on linux on Mac Book Pro
#!/bin/bash
file=/sys/devices/platform/applesmc.768/leds/smc::kbd_backlight/brightness
max_file=/sys/devices/platform/applesmc.768/leds/smc::kbd_backlight/max_brightness
level=$(cat $file)
changement_level=10
function change_brightness
@loiclefloch
loiclefloch / mixer-osd.sh
Created December 15, 2014 20:51
Alsamixer with aosd_cat
#!/bin/bash
# By Loic Lefloch
# Many thanks to crunchbang community and other contributors
#================================================================================
# Some user-defined values
MIXERNAME="Master" # The name of the amixer master device
GRANULARITY=32 # The approximate number of possible volume positions allowed
# aosd options
@loiclefloch
loiclefloch / UIViewController+BackButton.h
Created May 22, 2015 10:56
iOS change previous button globally
#import "UIViewController+BackButton.h"
#import <objc/runtime.h>
@implementation UIViewController (PMTBackButton)
+(void)load
{
Method viewWillAppear = class_getInstanceMethod(self, @selector(customViewWillAppear:));
Method customViewWillAppear = class_getInstanceMethod(self, @selector(viewWillAppear:));
@loiclefloch
loiclefloch / ViewController.swift
Created May 27, 2015 16:07
Horizontal Number Picker
class ViewController: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate {
@IBOutlet weak var dividerPickerViewContainer: UIView!
var dividerPickerView: UIPickerView = UIPickerView()
override func viewDidLoad() {
// dividerPicker
self.dividerPickerView.delegate = self
self.dividerPickerView.dataSource = self
@loiclefloch
loiclefloch / example.swift
Created June 8, 2015 13:06
Swift Keyboard handling
func viewDidLoad() {
super.viewDidLoad()
// Register to this notifications for handle reduction of the app
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("appWillResignActive"), name: UIApplicationWillResignActiveNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("appWillTerminate"), name: UIApplicationWillTerminateNotification, object: nil)
// Call end editing when the user tap on the screen but not in the keyboard or the text edit
var tapGesture = UITapGestureRecognizer(target: self, action: Selector("endEditing:"))
// prevents the scroll view from swallowing up the touch event of child buttons
@loiclefloch
loiclefloch / String.swift
Last active December 7, 2015 03:38
Swift usefull extensions
extension String
{
var length: Int {
get {
return count(self)
}
}
func contains(s: String) -> Bool
{
@loiclefloch
loiclefloch / FormViewController.swift
Created June 11, 2015 12:58
iOS form next button handling.
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWasShown:", name: UIKeyboardWillShowNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillBeHidden:", name: UIKeyboardWillHideNotification, object: nil)
}
override func viewWillDisappear(animated: Bool) {
NSNotificationCenter.defaultCenter().removeObserver(self)
}
@loiclefloch
loiclefloch / Regex.swift
Created June 16, 2015 16:41
Simplify regex with Swift
import Foundation
infix operator =~ {}
func =~ (input: String, pattern: String) -> Bool {
return Regex(pattern).test(input)
}
class Regex {
let internalExpression: NSRegularExpression
@loiclefloch
loiclefloch / BaseController.php
Last active November 5, 2015 23:01
Symfony REST API
<?php
namespace Example\ApiBundle\Controller;
use FOS\RestBundle\Controller\FOSRestController;
use FOS\RestBundle\View\View;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Serializer\Exception\LogicException;
use Symfony\Component\Validator\ConstraintViolation;
.text-xs-left { text-align: left; }
.text-xs-right { text-align: right; }
.text-xs-center { text-align: center; }
.text-xs-justify { text-align: justify; }
@media (min-width: 768px) {
.text-sm-left { text-align: left; }
.text-sm-right { text-align: right; }
.text-sm-center { text-align: center; }
.text-sm-justify { text-align: justify; }