Skip to content

Instantly share code, notes, and snippets.

View catwhocode's full-sized avatar

Cat who code catwhocode

  • Jakarta, Indonesia
  • 21:24 (UTC +07:00)
View GitHub Profile
@dbinit
dbinit / cherryd.py
Created November 18, 2011 20:49
CherryPy Django server
import os
import socket
import urllib
import urlparse
import cherrypy
# Django settings
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings')
# Celery loader
@jpallen
jpallen / unit-testing.md
Created August 24, 2012 14:02
Unit testing has made me a better programmer

This post is blatant rip-off of the post Backbone has made me a better programmer by Andy Appleton. His message is excellent and I encourage you to read it, but I wanted to show that writing well structured and decoupled code is something that can be learned from unit testing as well as Backbone. Unit testing will force you to write good code and this is a very strong reason why you should be doing it!

I started unit testing about a year ago and have since used it on large and small projects at work and for fun.

These last two months I have been refactoring some JavaScript on ShareLaTeX and I was really surprised at the state of the code I had written not all that long ago. I have been rewriting it to use a number of design patterns that I have necessarily picked up from unit testing.

One object one responsibility

We all write clean encapsulated ob

@scragg0x
scragg0x / gist:3894835
Created October 15, 2012 19:47
Unserialize PHP Session in Python
def unserialize_session(val):
if not val:
return
session = {}
groups = re.split("([a-zA-Z0-9_]+)\|", val)
if len(groups) > 2:
groups = groups[1:]
groups = map(None, *([iter(groups)] * 2))
for i in range(len(groups)):
@jlainezs
jlainezs / createcertificate.php
Last active February 10, 2023 15:22
Creates a certificate using OpenSSL with PHP. sing.php could be used to sign a text with the pkey generated with createCertificate. verify.java shows how to load the certificate from a resource and a verification sample of the text signed with sign.php
/**
* Creates an OpenSSL certificate
* @param $dn Array Associative array "key"=>"value"
* @param $duration int Number of days which the certificate is valid
* @throws Exception If there are any errors
* @return Array Associative array with the security elements: "cer"=>self signed certificate, "pem"=>private key, "file"=>path to the files
*
* @see http://www.php.net/manual/en/function.openssl-csr-new.php
* @author Pep Lainez
*/
<?php
class Parkir{
public function chekIn($idParkir,$statuss,$nopol,$timestart,$tanggal,$timeend){
$status=false;
//$dom = new DOMDocument("1.0","UTF-8");
//$parkirkendaraan = $dom->createElement("parkirkendaraan");
@labnol
labnol / google-apps-script.md
Last active March 25, 2024 14:50 — forked from junaidk/resources.md
How to Learn Google Apps Script

Learning Google Apps Script

Find the best resources for learning Google Apps Script, the glue that connects all GSuite services including Gmail, Google Drive, Calendar, Google Sheets, Forms, Maps, Analytics and more.

A good place to learn more about Google Apps Script is the official documentation available at developers.google.com. Here are other Apps Script resources that will help you get up to speed.

  1. Google Apps Script Code Samples by Amit Agarwal
  2. Google Apps Script Development - Create Google Apps Script projects locally inside VS Code - video tutorial
  3. Awesome Google Scripts by Amit Agarwal
  4. Google Developer Experts - Follow Apps Scr
@tuttelikz
tuttelikz / NaiveBayes.py
Last active June 25, 2023 16:03
Naive Bayes From Scratch in Python
#How To Implement Naive Bayes From Scratch in Python
#http://machinelearningmastery.com/naive-bayes-classifier-scratch-python/
#Dataset
#https://archive.ics.uci.edu/ml/machine-learning-databases/pima-indians-diabetes/pima-indians-diabetes.data
import csv
import math
import random
#Handle data
@Rich-Harris
Rich-Harris / service-workers.md
Last active July 10, 2024 17:04
Stuff I wish I'd known sooner about service workers

Stuff I wish I'd known sooner about service workers

I recently had several days of extremely frustrating experiences with service workers. Here are a few things I've since learned which would have made my life much easier but which isn't particularly obvious from most of the blog posts and videos I've seen.

I'll add to this list over time – suggested additions welcome in the comments or via twitter.com/rich_harris.

Use Canary for development instead of Chrome stable

Chrome 51 has some pretty wild behaviour related to console.log in service workers. Canary doesn't, and it has a load of really good service worker related stuff in devtools.

@surferxo3
surferxo3 / curl.php
Last active May 15, 2024 09:12
Script to demonstrate how to extract Header and Body from the Curl response in PHP.
<?php
/*#############################
* Developer: Mohammad Sharaf Ali
* Designation: Web Developer
* Version: 1.0
*/#############################
// SETTINGS
ini_set('max_execution_time', 0);
@ablunier
ablunier / PrintServerApi.php
Last active April 17, 2024 23:11
This a print connector implementation to communicate the mike42/escpos-php package with the ablunier/escpos-print-api API
<?php
namespace Ablunier\Escpos\PrintConnectors\Connectors;
use Mike42\Escpos\PrintConnectors\PrintConnector;
use GuzzleHttp\Client;
/**
* Class PrintServerApi
*/