Skip to content

Instantly share code, notes, and snippets.

View alimoeeny's full-sized avatar
💭
Strong Opinions Weakly Held

Ali Moeeny alimoeeny

💭
Strong Opinions Weakly Held
View GitHub Profile
@ninnemana
ninnemana / index.go
Created July 5, 2012 19:23
Testing out the encoding/csv package in golang
package main
import (
"encoding/csv"
"net/http"
"html/template"
"fmt"
"strconv"
)
@velyan
velyan / StateMachine.swift
Last active March 4, 2020 18:31
Swift State Pattern
import Foundation
fileprivate protocol Statelike {
var stateMachine: StateMachine { get }
func logIn()
func logOut()
}
extension Statelike {
func logIn() {}
@alimoeeny
alimoeeny / pre-commit
Last active June 9, 2020 13:27
git pre-commit hook for automatic versioning on every commit in golang
#!/bin/sh
#read more at http://alimoeenysbrain.blogspot.com/2013/10/automatic-versioning-with-git-commit.html
#replace all MYPROJECT with your project name
#for languages other than go (golang) replace all the .go extensions with your language extensions and modify BODY to reflect you language syntax
VERBASE=$(git rev-parse --verify HEAD | cut -c 1-7)
echo $VERBASE
NUMVER=$(awk '{printf("%s", $0); next}' MYPROJECTversion.go | sed 's/.*MYPROJECT\.//' | sed 's/\..*//')
echo "old version: $NUMVER"
[
{
"price": "USD 4.99",
"dollars": "4.99",
"country": "Algeria",
"countryCode": "DZA",
"link": "https://www.spotify.com/dz-fr/premium/",
"percentageOfUSA": 49,
"discount": 51
},
@intentionally-left-nil
intentionally-left-nil / deloldtweets.py
Last active July 27, 2022 10:33 — forked from flesueur/deloldtweets.py
Delete (very) old tweets obtained from a twitter archive
#!/bin/python3
# Largely copied from http://www.mathewinkson.com/2015/03/delete-old-tweets-selectively-using-python-and-tweepy
# However, Mathew's script cannot delete tweets older than something like a year (these tweets are not available from the twitter API)
# This script is a complement on first use, to delete old tweets. It uses your twitter archive to find tweets' ids to delete
# How to use it :
# - download and extract your twitter archive (tweet.js will contain all your tweets with dates and ids)
# - put this script in the extracted directory
# - complete the secrets to access twitter's API on your behalf and, possibly, modify days_to_keep
# - delete the few junk characters at the beginning of tweet.js, until the first '[' (it crashed my json parser)
# - review the script !!!! It has not been thoroughly tested, it may have some unexpected behaviors...
@mzaks
mzaks / Entitas-BT.cs
Last active September 5, 2022 11:55
Sketch for Entitas-CSharp Behaviour Tree implementation
// Based on http://www.gamasutra.com/blogs/ChrisSimpson/20140717/221339/Behavior_trees_for_AI_How_they_work.php
public enum NodeStatus
{
Success, Failure, Running
}
public interface IBehaviorNode
{
NodeStatus Execute(Entity entity);
@bhaettasch
bhaettasch / gensim_word2vec_demo.py
Created January 10, 2016 18:41
Use gensim to load a word2vec model pretrained on google news and perform some simple actions with the word vectors.
from gensim.models import Word2Vec
# Load pretrained model (since intermediate data is not included, the model cannot be refined with additional data)
model = Word2Vec.load_word2vec_format('GoogleNews-vectors-negative300.bin', binary=True, norm_only=True)
dog = model['dog']
print(dog.shape)
print(dog[:10])
# Deal with an out of dictionary word: Михаил (Michail)
@justecorruptio
justecorruptio / 2048.c
Created April 4, 2014 03:49
Tiny 2048 in C!
M[16],X=16,W,k;main(){T(system("stty cbreak")
);puts(W&1?"WIN":"LOSE");}K[]={2,3,1};s(f,d,i
,j,l,P){for(i=4;i--;)for(j=k=l=0;k<4;)j<4?P=M
[w(d,i,j++)],W|=P>>11,l*P&&(f?M[w(d,i,k)]=l<<
(l==P):0,k++),l=l?P?l-P?P:0:l:P:(f?M[w(d,i,k)
]=l:0,++k,W|=2*!l,l=0);}w(d,i,j){return d?w(d
-1,j,3-i):4*i+j;}T(i){for(i=X+rand()%X;M[i%X]
*i;i--);i?M[i%X]=2<<rand()%2:0;for(W=i=0;i<4;
)s(0,i++);for(i=X,puts("\e[2J\e[H");i--;i%4||
puts(""))printf(M[i]?"%4d|":" |",M[i]);W-2
@JohnCoates
JohnCoates / generateRandomPastelColor.swift
Last active December 5, 2022 14:20
Randomly generate pastel UIColor in Swift
// Adapted from Stack Overflow answer by David Crow http://stackoverflow.com/a/43235
// Question: Algorithm to randomly generate an aesthetically-pleasing color palette by Brian Gianforcaro
// Method randomly generates a pastel color, and optionally mixes it with another color
func generateRandomPastelColor(withMixedColor mixColor: UIColor?) -> UIColor {
// Randomly generate number in closure
let randomColorGenerator = { ()-> CGFloat in
CGFloat(arc4random() % 256 ) / 256
}
var red: CGFloat = randomColorGenerator()
@kellyegan
kellyegan / ViewController.swift
Last active April 2, 2023 00:57
Send emails with attachments in iOS using Swift
//
// ViewController.swift
// SendEmailWithAttachment
//
// Created by Kelly Egan on 3/17/15.
// Copyright (c) 2015 Kelly Egan. All rights reserved.
//
import UIKit
import MessageUI