Skip to content

Instantly share code, notes, and snippets.

View jweinst1's full-sized avatar
🎯
Focusing

Josh Weinstein jweinst1

🎯
Focusing
View GitHub Profile
@tanner0101
tanner0101 / IntExtensions.swift
Last active December 22, 2016 05:13
Convert an arbitrary length byte array into a Swift Int
/**
IntExtensions.swift
Convert an arbitrary length byte array into a Swift Int
<https://gist.github.com/tannernelson/e720877bf7700138eb99>
*/
extension Int {
static func fromByteArray(bytes: [UInt8]) -> Int {
@jweinst1
jweinst1 / noun, article and verb retrievers.js
Created September 13, 2015 06:14
noun and article searchers in js, also a slice array function and an array indexer.
//checks if the word is an article
function isarticleword(word) {
var article_words = ['the', 'an', 'a', 'this', 'those', 'that', 'these'];
for(i=0;i<article_words.length;i++) {
if (word == article_words[i]) {
return true;
}
}
return false;
}
@jweinst1
jweinst1 / probability toolkit.py
Last active September 24, 2015 07:57
probability toolkit.py
#prob function toolkit
from decimal import *
#takes a decimal probability
def chance(choose, total):
getcontext().prec = 6
return float(Decimal(choose)/Decimal(total))
#checks probability of choosing elem from a lst.
def occurence(elem, lst):
getcontext().prec = 6
@rvl
rvl / git-pushing-multiple.rst
Created February 9, 2016 11:41
How to push to multiple git remotes at once. Useful if you keep mirrors of your repo.

Pushing to Multiple Git Repos

If a project has to have multiple git repos (e.g. Bitbucket and Github) then it's better that they remain in sync.

Usually this would involve pushing each branch to each repo in turn, but actually Git allows pushing to multiple repos in one go.

If in doubt about what git is doing when you run these commands, just

@jweinst1
jweinst1 / readlineprompt.js
Created February 15, 2016 18:11
basic program to read lines and emit a response
#!/usr/bin/env node
var readline = require('readline'),
rl = readline.createInterface(process.stdin, process.stdout);
rl.setPrompt('TTT> ');
rl.prompt();
rl.on('line', function(line) {
switch(line.trim()) {
case 'hello':
@jweinst1
jweinst1 / regexswiftextensions.swift
Created March 6, 2016 23:16
allows for regex extending in swift
//extension that allows to test for a match in a string
extension String {
func matchPattern(patStr:String)->Bool {
var isMatch:Bool = false
do {
let regex = try NSRegularExpression(pattern: patStr, options: [.CaseInsensitive])
let result = regex.firstMatchInString(self, options: NSMatchingOptions(rawValue: 0), range: NSMakeRange(0, characters.count))
if (result != nil)
{
function makeIterator(array){
var nextIndex = 0;
return {
next: function(){
return nextIndex < array.length ?
{value: array[nextIndex++], done: false} :
{done: true};
}
};
@btfak
btfak / useHexo.md
Created May 26, 2016 09:41
How to use Hexo and deploy to GitHub Pages
@laobubu
laobubu / ABOUT.md
Last active July 23, 2025 16:33
A very simple HTTP server in C, for Unix, using fork()

Pico HTTP Server in C

This is a very simple HTTP server for Unix, using fork(). It's very easy to use

How to use

  1. include header httpd.h
  2. write your route method, handling requests.
  3. call serve_forever("12913") to start serving on port 12913
case class Gen[A](g: () => A) {
/*
* Evaluates a Gen, yielding a value
*/
def sample: A = {
g()
}
/*