Skip to content

Instantly share code, notes, and snippets.

View cypres's full-sized avatar

Hans Arnholm cypres

View GitHub Profile
@cypres
cypres / int-concat.cc
Last active August 29, 2015 14:02
Bench of integer concats
#include "time.h"
#include "math.h"
#include "assert.h"
#include <string>
// After http://ideone.com/hbWgE
int num_tests = 5000000;
unsigned duck(unsigned x, unsigned y) {
@cypres
cypres / fix_permissions.sh
Created July 11, 2014 10:45
Fix permissions script
#!/bin/sh
PATH=/var/www
USER=ftp
GROUP=www
# do an early exit if another find command is already running
/bin/ps axc | /usr/bin/awk '{ print $5 }' | /usr/bin/grep -q find
if [ $? -eq 0 ]; then
exit;
@cypres
cypres / oauth.cc
Last active January 23, 2021 16:39
Two-legged OAuth 1.0a in C++11
//
// Two-legged OAuth 1.0a proof of concept
// Feel free to use, copy or modify to your own needs.
//
// Requires glog, gflags and crypto++ (cryptopp.com)
// Compile with:
// clang++ -std=c++11 -lcryptopp -lglog -lgflags oauth.cc -o oauth_test
// Run with:
// ./oauth_test -alsologtostderr
//
@cypres
cypres / Easter.swift
Last active March 27, 2021 17:08
Easter calculation in Swift
// Easter calculation in swift after Anonymous Gregorian algorithm
// Also known as Meeus/Jones/Butcher algorithm
import Foundation
func easter(Y : Int) -> NSDate {
let a = Y % 19
let b = Int(floor(Double(Y) / 100))
let c = Y % 100
let d = Int(floor(Double(b) / 4))
@cypres
cypres / cidr.cc
Last active March 6, 2020 17:03
IPv4 in CIDR
#ifdef __FreeBSD__
#include <sys/socket.h>
#endif
#include <arpa/inet.h>
#include <netinet/in.h>
#include <cstdlib>
#include <cstring>
#include <cerrno>
#include <cassert>
#include <iostream>
@cypres
cypres / UIImageTint.swift
Last active August 15, 2016 07:24
Tinting UIImage with Overlay (preserving grey scale info)
import UIKit
extension UIImage {
func imageGreyScale() -> UIImage {
let imageRect = CGRectMake(0, 0, self.size.width, self.size.height)
let greyContext = CGBitmapContextCreate(
nil, UInt(self.size.width*self.scale), UInt(self.size.height*self.scale),
8, 0,
CGColorSpaceCreateDeviceGray(),
@cypres
cypres / keybase.md
Last active January 27, 2024 22:25
keybase.md

Keybase proof

I hereby claim:

  • I am cypres on github.
  • I am cyp (https://keybase.io/cyp) on keybase.
  • I have a public key ASCyjHoIq03nYt0VUveLHEBUrR6cQWFWhghU5OmD5npNLQo

To claim this, I am signing this object:

@cypres
cypres / .ycm_extra_conf.py
Created October 6, 2014 13:38
YouCompleteMe extra conf
# This file is NOT licensed under the GPLv3, which is the license for the rest
# of YouCompleteMe.
#
# Here's the license text for this file:
#
# This is free and unencumbered software released into the public domain.
#
# Anyone is free to copy, modify, publish, use, compile, sell, or
# distribute this software, either in source code form or as a compiled
# binary, for any purpose, commercial or non-commercial, and by any
@cypres
cypres / ssl_params
Created October 17, 2014 14:43
SSL config to keep IE6 on XP Support and Forward Secrecy - yet mitigate POODLE and BEAST server side
# For nginx. Requires OpenSSL 1.0.1j
ssl_ciphers EECDH+ECDSA+AESGCM:EECDH+aRSA+AESGCM:EECDH+ECDSA+SHA384:EECDH+ECDSA+SHA256:EECDH+aRSA+SHA384:EECDH+aRSA+SHA256:EECDH+aRSA+RC4:EECDH:EDH+aRSA:RC4:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!SRP:!DSS:!CAMELLIA;
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
@cypres
cypres / hello.php
Created October 31, 2014 12:39
nimta.com gateway hello world
<?php
(new SoapClient('https://soap.nimta.com?wsdl'))->sendSMSes(array(
'username' => 'USERNAME',
'password' => 'PASSWORD',
'gatewayClass' => 'A',
'messages' => array(
array(
'message' => 'Hello World!',
'charge' => 0,
'delayed' => false,